0

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!!!

1 Answer 1

1

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);
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.