Build your web apps using Smart UI
Smart.Grid - Export Selected Records
Export Selected Records in Grid Component
Smart.Grid's export functionality allows the export of all data in various formats (such as XLSX, PDF, and HTML), as well as the export of only particular records of the Grid. This help topic shows how to export only the data of selected rows in the Grid.
The following TypeScript code shows how to export selected Grid rows to XLSX. Its functionality is detailed below.
const grid = <Grid>document.getElementById('grid'), selection = grid.getSelection(); // (1) let rowIdsToExport: (string | number)[]; if (selection.rows) { rowIdsToExport = selection.rows.map((rowInfo: any) => rowInfo.row.id); // (2) } else { rowIdsToExport = []; } grid.dataExport!.rowIds = rowIdsToExport; //(3) grid.exportData('xlsx'); //(4)
- We get the Grid's selected row's by calling the method getSelection. If any records are selected, the object returned by this method contains a rows field - an array of objects with information about selected rows.
- This selected rows array is then converted to an array of row ids via map.
- The array of row ids to export is passed to the Grid's dataExport.rowIds property. Its default value is null, meaning that all records will be exported.
- Finally, the Grid's exportData method is called. In this case, the selected rows are exported to XLSX, but the Grid can also be exported to CSV, HTML, JPEG, PNG, JSON, PDF, TSV, and XML.
Note: If at a later time you wish to export all Grid rows, the dataExport.rowIds has to be reset by setting it to null.