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

Kendo UI grid excelExport failure

1 Answer 529 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Debbie
Top achievements
Rank 1
Debbie asked on 18 Jan 2017, 01:30 PM

I am trying to export  my master and detail grid to an excel file without success.

When I am debugging I can see that the function $.when.apply(null, detailExportPromises) isn't called.

The detail grid data is found correctly, but no Excel file is downloaded.

My code:

//Add export to excel option for main grid
    gridElement.data("kendoGrid").setOptions({
        excel: {
            allPages: true,
            fileName: "Pikdonot.xlsx",
            filterable: true
        },
        excelExport: function (e) {
            debugger;
            e.preventDefault();
            var workbook = e.workbook;
            detailExportPromises = [];
            var masterData = e.data;
            for (var rowIndex = 0; rowIndex < masterData.length; rowIndex++) {
                exportChildData(masterData[rowIndex].uid, rowIndex);
            }
            debugger;
            $.when.apply(null, detailExportPromises)
            .then(function () {
                debugger;
                // 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[0].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: "PikdonotDetails.xlsx"
                });
            });
        },
        toolbar: ["excel"]
    });

 

function exportChildData(uid, rowIndex) {
    debugger;
    var deferred = $.Deferred();
    detailExportPromises.push(deferred);
    var rows = [{
        cells: [
          // First cell
          { value: "YaadPeraon" },
          // Second cell
          { value: "TaarichErech" },
          // Third cell
          { value: "AdditionalDetails" },
          // Fourth cell
          { value: "IsNew" }
        ]
    }];
    var grid = $('#depositsResultGrid').find("tr[data-uid='" + uid + "']").next().find(".closedDepositTrackingResultGrid").data("kendoGrid");
    if (grid) {
        var data = grid.dataSource.data();
        var exporter = new kendo.ExcelExporter({
            columns: [{
                field: "YaadPeraon"
            }, {
                field: "TaarichErech"
            }, {
                field: "AdditionalDetails"
            }, {
                field: "IsNew"
            }],
            dataSource: {
                data: data
            }
        });
        exporter.workbook().then(function (book, data) {
            debugger;
            deferred.resolve({
                masterRowIndex: rowIndex,
                sheet: book.sheets[0]
            });
        });
    }
}

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 20 Jan 2017, 09:47 AM
Hello Debbie,

This is not a known issue and it was not reproduced on my side.

Please check the following Dojo example demonstrating a similar approach which is working as expected:

http://dojo.telerik.com/UveDu

If additional assistance is needed, please provide a fully runnable example and I will investigate further.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
Grid
Asked by
Debbie
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or