This is a migrated thread and some comments may be shown as answers.

Kendo Grid Export to Excel is working on Local, but not on STAGE

1 Answer 132 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gopal
Top achievements
Rank 1
Gopal asked on 13 Oct 2016, 11:28 AM

Hi, My Html Code is:

   <div kendo-grid="vm.grid" id="grid" k-data-source="vm.gridOptions.datasource" k-options="vm.gridOptions" class="lm-panel-body">
    </div>

 

And My Js file code in AngularJs is:

---------------------------------------------------

vm.getGridOptions = function () {
            vm.gridOptions = {
                datasource: new kendo.data.DataSource({
                    type: "odata",
                    transport: {
                        read: function (options) {
                            if (!!$scope.figure.figureId) {
                                if (!!options.data.filter) {
                                    $scope.filterChanged(vm.gridOptions.datasource, vm.getFigureData.dataSource.name);
                                    if (options.data.filter.filters != null) {
                                        for (var i = 0; i < options.data.filter.filters.length; i++) {
                                            if (options.data.filter.filters[i].value.indexOf("00:00:00") > -1) {
                                                var date = new Date(options.data.filter.filters[i].value);
                                                var month = ("0" + (date.getMonth() + 1)).slice(-2);
                                                var day = ("0" + date.getDate()).slice(-2);
                                                var fullDate = date.getFullYear() + "/" + month + "/" + day;
                                                options.data.filter.filters[i].value = fullDate;
                                            }
                                        }
                                    }
                                }
                                else if (!options.data.filter)
                                {
                                    $scope.filterChanged(undefined, vm.getFigureData.dataSource.name);
                                }
                                gridService.get(options, $scope.figure.figureId).then(function (data) {
                                });
                            }
                        }
                    },
                    schema: {
                        data: function (data) {
                            if (data.data) {
                                return data.data;
                            }
                        },
                        total: function (data) {
                            if (data.total) {
                                return data.total;
                            }
                        }
                    },
                    group: vm.JsonGroupingCloumns,
                    aggregate: vm.aggregatesList,
                    pageSize: vm.gridConfigurationJson.PageSize ? vm.gridConfigurationJson.PageSize : 10,
                    serverPaging: true,
                    serverSorting: true,
                    serverFiltering: true
                }),
                dataBound: function (e) {
                    if (vm.childGridId > 0 && vm.detailGridFigureParams == undefined) {
                        this.expandRow(this.tbody.find("tr.k-master-row").first());
                        this.collapseRow(this.tbody.find("tr.k-master-row").first());
                    }
                    if (e.sender.pager.dataSource._pageSize != 10) {
                        if (vm.gridConfigurationJson.PageSize != e.sender.pager.dataSource._pageSize) {
                            saveGridConfigration(e, $scope.figure.figureId);
                        }
                    }
                },
                sortable: {
                    mode: "single",
                    allowUnsort: false
                },
                pageable: {
                    refresh: true,
                    pageSizes: [10, 25, 50, 100, 200, "All"],
                    buttonCount: 5,
                },
                filterable:true,
                scrollable: true,
                resizable: true,
                reorderable: true,
                columnMenu: true,
                columns: vm.columnsList,
                excel: {
                    allPages: true,
                    filterable: true
                },
                excelExport: function (e) {
                    var filename = "";
                    if ($scope.figure.captionView != undefined) {
                        filename = $scope.figure.captionView;
                    }
                    else if ($scope.figure.caption != undefined) {
                        filename = $scope.figure.caption;
                    }
                    if (vm.childGridId > 0)
                    {
                        e.preventDefault();
                        var workbook = e.workbook;

                        detailExportPromises = [];
                        
                        var masterData = e.data;

                        if (masterData != null) {
                            for (var rowIndex = 0; rowIndex < masterData.length; rowIndex++) {
                                var masterRowData = {};
                                masterRowData.data = masterData[rowIndex];
                                exportChildData(rowIndex, masterRowData);
                            }
                        }

                        $.when.apply(null, detailExportPromises)
                                   .then(function () {
                                       // get the export results
                                       var detailExports = $.makeArray(arguments);

                                       // sort by masterRowIndex
                                       detailExports.sort(function (a, b) {
                                           return a.masterRowIndex - b.masterRowIndex;
                                       });

                                       //// add an empty column
                                       workbook.sheets[0].columns.unshift({
                                           width: 30
                                       });

                                       // prepend an empty cell to each row
                                       for (var i = 0; i < workbook.sheets[0].rows.length; i++) {
                                           workbook.sheets[0].rows[i].cells.unshift({});
                                       }

                                       // merge the detail export sheet rows with the master sheet rows
                                       // loop backwards so the masterRowIndex doesn't need to be updated
                                       for (var i = detailExports.length - 1; i >= 0; i--) {
                                           var masterRowIndex = detailExports[i].masterRowIndex + 1; // compensate for the header row

                                           var sheet = detailExports[i].sheet;

                                           // prepend an empty cell to each row
                                           for (var ci = 0; ci < sheet.rows.length; ci++) {
                                               if (sheet.rows[ci].cells[1].value) {
                                                   sheet.rows[ci].cells.unshift({});
                                               }
                                           }

                                           // insert the detail sheet rows after the master row
                                           [].splice.apply(workbook.sheets[0].rows, [masterRowIndex + 1, 0].concat(sheet.rows));
                                       }

                                       // save the workbook

                                       kendo.saveAs({
                                           dataURI: new kendo.ooxml.Workbook(workbook).toDataURL(),
                                           fileName: filename + ".xlsx"
                                       });
                                   });
                    }else
                    {
                       e.workbook.fileName = filename + ".xlsx";
                    }
                },
                //pdf: {
                //    allPages: true,
                //    fileName: $scope.vm.getFigureData.caption + ".pdf"
                //},
                columnReorder: function (e) {
                    saveGridConfigration(e,$scope.figure.figureId);
                },
                columnResize: function (e) {
                    saveGridConfigration(e,$scope.figure.figureId);
                }
            };
            if (vm.childSourceChecked == 1) {
            if (vm.childGridId > 0) {
                    vm.gridOptions.detailInit = detailInit;
                }
                vm.childSourceChecked = 2;
            }
            var clearFilterTemplate = $("#clearFilterButtonTemplate").html();
            if(clearFilterTemplate)
            {
                vm.gridOptions.toolbar = [
                    "excel",
                    { text: "Clear filter", template: kendo.template($("#clearFilterButtonTemplate").html()) }
                ]
            }

        };

Error is Google Chrome :

lib-0fb5682e33.js:5 TypeError: Cannot read property 'length' of undefined
    at Function.map (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:1:12661)
    at init.toDataURL (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:24:1105)
    at init.<anonymous> (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:24:9157)
    at Object.r (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:1:12947)
    at Object.<anonymous> (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:2:4784)
    at u (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:2:3416)
    at Object.fireWith [as resolveWith] (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:2:4228)
    at Object.r.(anonymous function) [as resolve] (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:2:5208)
    at init.<anonymous> (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:24:3882)
    at Object.r (http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:1:12947)

 

Error in Firefox is:

Error: e is undefined
.map@http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:1:12658
z<.toDataURL@http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:24:1103
t.ExcelMixin.saveAsExcel/<@http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:24:9155
.proxy/r@http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:1:12945
.Deferred/i.then/</</<@http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:2:4782
J.Callbacks/u@http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:2:3411
J.Callbacks/d.fireWith@http://lm.stage.cargoclix.net/js/lib-0fb5682e33.js:2:4228

1 Answer, 1 is accepted

Sort by
0
Katia
Telerik team
answered on 14 Oct 2016, 06:34 AM
Hello Gopal,

This is Telerik Reporting forum.

For questions regarding Kendo UI controls please post in the respective forum - Kendo UI Forum.


Regards,
Katia
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Gopal
Top achievements
Rank 1
Answers by
Katia
Telerik team
Share this question
or