How to remove all rows in AgGrid

There is no data API in AgGrid, therefore we use Grid API instead.

// .ts file, and variable *grid* is declared like:
// @ViewChild('grid', { static: true }) grid: AgGridAngular;
const oldData = [];
this.grid.gridOptions.api.forEachNode(r => oldData.push(;
this.grid.gridOptions.api.applyTransaction({ remove: oldData });


If we want to clear grid properly, we need do step by step:

  1. Reset columnDefs to an empty array.
  2. Fetch all existing raw data.
  3. Remove all existing raw data by applyTransaction.