How can I get all the rows of ag-grid?

Sandeep Kumar picture Sandeep Kumar · Jun 5, 2018 · Viewed 24.3k times · Source

ag-grid provides a way to get selected rows using api.getSelectedRows() function. And provides a way to set all rows using api.setRowData([]) function. I'm looking for something getAllRows() to return all the rows in the grid. I know there is a way to loop through all the rows using api.forEachNode() etc. Is there any way I can get the entire array of rows?

Answer

Michael Karén picture Michael Karén · Jun 6, 2018

I don't think there is such a method but you can make your own:

getAllRows() {
  let rowData = [];
  this.gridApi.forEachNode(node => rowData.push(node.data));
  return rowData;
}