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

Save As Excel Callback

8 Answers 1810 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Veteran
Scott asked on 18 Jul 2016, 04:37 PM

What I would like to do is call the Save As Excel from an external button, show a progress spinner instead of the button, and when the export is finished show the button again.  This is to let the user know longer running exports are processing and not to keep clicking the button.

Here is some example code that fires the hide immediately after the save is called.

$('#export').click(function (e) {     
    showProgress();     
    e.preventDefault();     
    $('#Results').getKendoGrid().saveAsExcel();     

    // Bug: This processes immediately, need to wait for saveAsExcel to finish.     
    hideProgress();
});

8 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 20 Jul 2016, 06:51 AM

Hello Scott,

You could attach a handler to the excelExport event of the Grid and hide the progress in the event handler.

Regards,
Dimiter Madjarov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Scott
Top achievements
Rank 1
Veteran
answered on 20 Jul 2016, 10:00 PM
That works.  Thanks.
0
Scott
Top achievements
Rank 1
Veteran
answered on 20 Jul 2016, 10:00 PM
That works.  Thanks.
0
Peter
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 18 Mar 2021, 01:07 PM

Hi,

for a large Excel-File (8MB) the excelExport event fire to early:

It need 8 second to show the log:

function ExcelExport(e: any) {
     e.workbook.fileName = "excelexport.xlsx";
     console.log("export to " + e.workbook.fileName);
 }

 

but total 26 second until the download is completed.

Is there an event 'ExcelDownloadCompleted' ?

I want disable the toolbar Export button until the download is completed.

Peter

0
Tsvetomir
Telerik team
answered on 22 Mar 2021, 07:48 AM

Hi Peter,

Currently, the Kendo UI Grid does not expose an event to track when a file has been downloaded. This is due to the fact that the actual export is not part of the duties of the grid. The grid only says 'export this data' and does not know anything else about the process. 

What I can recommend is that you disable the button within the ExcelExport event and set a setTimeout function that would make the button active after a certain period of time. Of course, you should set it according to the export time of your application.

 

Kind regards,
Tsvetomir
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Peter
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 22 Mar 2021, 09:14 AM

Hi Tsvetomir,

I use the code from Progress Indicator for exporting to excel

var grid;

 function StartExcelExport(e) {

        kendo.ui.progress($("#grid"), true);
        toolbar.enable("#idexportButton", false); //disables Toolbar Button
        grid.saveAsExcel();
    }
    function ExcelExport(e: any) {
        // overriding the export event here allows us to insert
        // the progress indicators, and hide them when the save complete             
        e.preventDefault();
 
        $.when(function () {
            var def = jQuery.Deferred();
            window.setTimeout(function () {
                var workbook = new kendo.ooxml.Workbook(e.workbook);
                kendo.saveAs({
                    dataURI: workbook.toDataURL(),
                    fileName: "Exportfile.xlsx",
                    proxyURL: $("#grid").data("kendoGrid").options.excel.proxyURL
                });
                def.resolve();
            }, 100);
            return def.promise();
        }())
            .done(function () {
                kendo.ui.progress($("#grid"), false);
                toolbar.enable("#idexportButton", true); //enable Toolbar Button
            });
    }
 

In Init Code:

                $("#toolbar").kendoToolBar({
                    items: [{
                        id: "idexportButton",
                        type: "button",
                        text: "Export",
                        icon: "file-excel",
                        click: StartExcelExport
                    }
                    ]
                });
                grid = $("#grid").data("kendoGrid");
                grid.bind("excelExport", ExcelExport);
            });

 

Best regards,

Peter

0
Peter
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 22 Mar 2021, 12:02 PM

I forgot to copy the toolbar variable:

var toolbar;
 
// in Init code:
toolbar = $("#toolbar").data("kendoToolBar");
0
Tsvetomir
Telerik team
answered on 23 Mar 2021, 12:38 PM

Hi Peter,

Thank you for taking the time to share with the community the approach that you have undertaken.

However, I am not completely sure whether you have successfully integrated the suggestion into your application. Can you confirm that there are no issues with the project on your side? If not, could you share any questions that you might have with your next response?

 

Kind regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Veteran
Answers by
Dimiter Madjarov
Telerik team
Scott
Top achievements
Rank 1
Veteran
Peter
Top achievements
Rank 2
Iron
Veteran
Iron
Tsvetomir
Telerik team
Share this question
or