aswininayak
aswininayak

Reputation: 973

ag-grid 20 with Angular 6 export functionality

Need help to export some records in ag-grid.

I am trying to export(csv) certain records from ag-grid in my application. I can't use rowSelection. Manually selecting some records and wants to export those records only.

  const selectedRows = [{name: 'A'}, {name: 'b'}];

   const params = {
    skipHeader: false,
    columnKeys: ['name'],
    fileName: 'Test_' + Date.now()
  };

  this.GridOptions.api.exportDataAsCsv(params);

Here how can I pass the selectedRows to the API?

Thanks in advance!!!

Upvotes: 0

Views: 450

Answers (1)

abd995
abd995

Reputation: 1839

You can programatically select the desired RouterLinkWithHref, ask ag-grid to export the selected rows and then deselect them after printing if necessary.

  const selectedRows = [{name: 'A'}, {name: 'b'}];

  this.GridOptions.api.forEachNode((node) => {
    // Check to determine if the row should be selected for printing
    // Replace with your logic if necessary
    if (selectedRows.findIndex((x) => x.name === node.data.name)) {
      // select the row
      node.setSelected(true);
    } else {
      // deselect the row
      node.selected(false);
    }
  });

   const params = {
    // only selected rows will be exported
    onlySelected: true,
    skipHeader: false,
    columnKeys: ['name'],
    fileName: 'Test_' + Date.now()    
  };

  this.GridOptions.api.exportDataAsCsv(params);

  // deselect all rows
  this.GridOptions.api.foreachNode((node) => {
      node.setSelected(false);
  });

Upvotes: 1

Related Questions