Export Selected Grid Rows to Excel
Environment
| Product | Progress® Kendo UI for Angular Grid |
Description
How can I export only the selected rows of the Kendo UI for Angular Grid to Excel?
This article also answers the following questions:
- How can I export checked rows from the Grid?
- What is the method to export selected grid rows to Excel in Angular?
- How to use selection in the Kendo UI Grid for Angular to export to Excel?
Solution
The following example demonstrates how to export only selected rows to Excel.
By default, the Excel export functionality of the Grid generates a file containing the current data of the component. To export specific data to Excel that includes only the selected Grid rows:
-
Use the
kendoGridSelectBydirective of the Grid to store the selected items in theselectedKeyscollection that the directive provides:html<kendo-grid ... kendoGridSelectBy [(selectedKeys)]="mySelection" ></kendo-grid> -
Use the
fetchDatacallback of theExcelComponentto specify the data to be exported in Excel.html<kendo-grid ... > ... <kendo-grid-excel [fetchData]="allData" fileName="Products.xlsx" ></kendo-grid-excel> </kendo-grid>In the
fetchDatacallback, return anExcelExportDataobject that contains only the items that are selected according to theselectedKeyscollection.Make sure the
fetchDatahandler is an arrow function which retains the correctthiscontext.tspublic mySelection: number[] = []; public selectedData = ():ExcelExportData =>{ const result = { data: this.mySelection, }; return result; }