Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get filtered rows in ag-grid?

I have an ag-Grid with filtering option.

How to get the filtered rows (not the selected) in ag-Grid?

like image 477
Gábor Csikós Avatar asked Apr 21 '17 11:04

Gábor Csikós


3 Answers

You can use the forEachNodeAfterFilter(callback) api method for this.

See https://www.ag-grid.com/javascript-grid-api for all available API calls, including the various forEachXXX methods.

like image 147
Sean Landsman Avatar answered Oct 09 '22 04:10

Sean Landsman


Building off @sean-landsman's answer, here's an example of how to use the forEachNodeAfterFilter(callback) method:

    let rowData = [];
    gridApi.forEachNodeAfterFilter(node => {
      rowData.push(node.data);
    });
like image 6
Atanu Mallick Avatar answered Oct 09 '22 06:10

Atanu Mallick


This took me forever so I'm posting here. Use onFilterChanged() to access the filtered rows, or the filtered + selected rows. The event passed to onFilterChanged() can be used like so (example in Typescript React)

onFilterChanged = ev => {
  if (ev?.api?.rowModel?.rowsToDisplay) {
    this.setState({ selectedRows: ev?.api?.rowModel?.rowsToDisplay.filter(node => node.isSelected()) });
  }
};
like image 5
Andrew Avatar answered Oct 09 '22 05:10

Andrew