18

I have an ag-Grid with filtering option.

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

Gábor Csikós
  • 2,787
  • 7
  • 31
  • 57

5 Answers5

15

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.

Sean Landsman
  • 7,033
  • 2
  • 29
  • 33
8

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);
    });
Whit Waldo
  • 4,806
  • 4
  • 48
  • 70
Atanu Mallick
  • 266
  • 4
  • 7
5

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()) });
  }
};
Andrew
  • 1,406
  • 1
  • 15
  • 23
0

You can use getSelectedNodes() and filter() them for filtering hidden rows.

this.gridApi.getSelectedNodes().filter(node => node.displayed).map(node => node.data)
t.saagar
  • 1
  • 1
0

There is selectAllFiltered() function now:

https://www.ag-grid.com/angular-data-grid/grid-api/?#reference-selection-selectAllFiltered

erien
  • 1