Export multiple grids to excel file with all pages

3 posts, 0 answers
  1. Matias
    Matias  avatar
    24 posts
    Member since:
    Mar 2016

    Posted 17 Oct Link to this post

    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. Matias
    Matias  avatar
    24 posts
    Member since:
    Mar 2016

    Posted 18 Oct Link to this post

    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.

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 19 Oct Link to this post

    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
Back to Top