Export to Excel a Limited Number of Rows

Environment

Product Version 2017.3 1026
Product Progress Kendo UI Grid for ASP.NET MVC

Description

How can I set a configurable limit to the number of the Grid rows that are exported to Excel?

Solution

Split the array of the exported rows based on a value during the excelExport event.

<div id="grid"></div>
    <script>
      var numerOfrows = 5 // the number of the exported rows
      $("#grid").kendoGrid({
        toolbar: ["excel"],
        excelExport: function(e) { sheet = e.workbook.sheets[0];
          var newSheet = sheet.rows.splice(0, numerOfrows + 1) // +1 is for the header row
          e.workbook.sheets[0].rows = newSheet
        },
        dataSource: {
          data: [
            { text: "Positive", value: 10.5 },
            { text: "Negative", value: -10.5 },
            { text: "Zero", value: 0 },
            { text: "Positive", value: 10.5 },
            { text: "Negative", value: -10.5 },
            { text: "Zero", value: 0 },
            { text: "Positive", value: 10.5 },
            { text: "Negative", value: -10.5 },
            { text: "Zero", value: 0 },            { text: "Positive", value: 10.5 },
            { text: "Negative", value: -10.5 },
            { text: "Zero", value: 0 }
          ]
        }
      });
    </script>
In this article
Not finding the help you need? Improve this article