How to export excel of selected record in Ignite UI in Angular

542 Views Asked by At

I am using Ignite UI. In that I am using Igx grid, I am able to export excel of all data using IgxExcelExporterService, but I want to export only selected data by using onRowSelectionChange method of igx grid. Is there any way igx-grid support this functionality?

1

There are 1 best solutions below

0
On

You can use the Excel Exporter service:

this.excelExportService.exportData(this.data, ..).

Go ahead and pass a data array to the service. How to fill the data array with the selected rows data? Here you can find a code snippet for bootstrapping your POC:

Actual code:

public clicked() {
  let selectedRows = this.grid1.selectedRows;

  for (let rowIndex of selectedRows) {
    let rowData = this.grid1.getRowByIndex(rowIndex).rowData;
    this.exportData.push(rowData);
  }
  console.log(this.exportData);
  this.excelExportService.exportData(this.exportData,
                                     new IgxExcelExporterOptions("ExportedDataFile"));

  this.exportData = [];
}

This Export excel topic will help you any further.

Use this for a starting point with the igxGrid row selection.