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

Export multiple grids to excel file with all pages

2 Answers 755 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matias
Top achievements
Rank 1
Matias asked on 17 Oct 2016, 05:23 PM

Hi, I'm using a solution for exporting several grids to one excel file and it works great, but it only exports the current page of the application. Is there any way I can export all pages of the grids? Just like this:

.Excel(excel => excel
      .FileName("Reporte.xlsx")
      .Filterable(true)
      .AllPages(true)
      .ProxyURL(Url.Action("Excel_Export_Save", "Export"))
      )

 

This is my current solution:

In the grids I have am Event trigger:

.Events(e => e.ExcelExport("pendientes_excelExport"))

 

And then a js function, fired by a button click:

// used to sync the exports
    var promises = [
      $.Deferred(),
      $.Deferred(),
      $.Deferred(),
      $.Deferred(),
      $.Deferred()
    ];

    $("#export").click(function (e) {
        // trigger export of the grids
        
        $("#grillaOrigen1").data("kendoGrid").saveAsExcel();
        $("#grillaOrigen2").data("kendoGrid").saveAsExcel();
        $("#grillaConciliadas").data("kendoGrid").saveAsExcel();
        $("#grillaManuales").data("kendoGrid").saveAsExcel();
        $("#grillaPendientes").data("kendoGrid").saveAsExcel();

        // wait for exports to finish
        $.when.apply(null, promises)
         .then(function (grillaOrigen1Workbook, grillaOrigen2Workbook, grillaConciliadasWorkbook, grillaManualesWorkbook, grillaPendientesWorkbook) {

             // create a new workbook using the sheets of workbooks
             var sheets = [
               grillaOrigen1Workbook.sheets[0],
               grillaOrigen2Workbook.sheets[0],
               grillaConciliadasWorkbook.sheets[0],
               grillaManualesWorkbook.sheets[0],
               grillaPendientesWorkbook.sheets[0]
             ];

             sheets[0].title = "Origen1";
             sheets[1].title = "Origen2";
             sheets[2].title = "Conciliadas";
             sheets[3].title = "Manuales";
             sheets[4].title = "Pendientes";

             var workbook = new kendo.ooxml.Workbook({
                 sheets: sheets
             });

             // save the new workbook
            kendo.saveAs({
                dataURI: workbook.toDataURL(),
                fileName: "Conciliacion.xlsx"
            });
        });
    });

    function origen1_excelExport(e) {
        e.preventDefault();

        promises[0].resolve(e.workbook);
    }

    function origen2_excelExport(e) {
        e.preventDefault();

        promises[1].resolve(e.workbook);
    }

    function conciliadas_excelExport(e) {
        e.preventDefault();

        promises[2].resolve(e.workbook);
    }

    function manuales_excelExport(e) {
        e.preventDefault();

        promises[3].resolve(e.workbook);
    }

    function pendientes_excelExport(e) {
        e.preventDefault();

        promises[4].resolve(e.workbook);
    }

 

Thank you very much

2 Answers, 1 is accepted

Sort by
0
Matias
Top achievements
Rank 1
answered on 18 Oct 2016, 01:06 PM

If anyone is struggling to make this work, how's you gotta do it. In every grid you gotta have the following code:

.Excel(excel => excel
                .Filterable(true)
                .AllPages(true)
          )

Done. This will export every grid with filters and every row.

0
Eyup
Telerik team
answered on 19 Oct 2016, 05:25 AM
Hello Matias,

Thank you for sharing your specific approach with our community. I hope it will prove helpful to other developers as well.

In addition, you can also check the following articles, if you haven't already:
http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/excel-export#export-all-data
http://docs.telerik.com/kendo-ui/controls/data-management/grid/pdf-export#export-of-all-pages

You can refer to the following post for achieving this requirement using a custom configuration:
http://www.telerik.com/forums/multiple-excel-export-buttons-on-grid


Regards,
Eyup
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
Grid
Asked by
Matias
Top achievements
Rank 1
Answers by
Matias
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or