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;
this.grid.gridOptions.api.setColumnDefs([]);
const oldData = [];
this.grid.gridOptions.api.forEachNode(r => oldData.push(r.data));
this.grid.gridOptions.api.applyTransaction({ remove: oldData });
Conclusion
If we want to clear grid properly, we need do step by step:
- Reset
columnDefs
to an empty array. - Fetch all existing raw data.
- Remove all existing raw data by
applyTransaction
.