Currently, I am using a for loop to iterate over an array and dynamically creating ag-grid based on its content. With the data available, I am preselecting certain rows in the ag-grid.
For the gridReady method:
onGridReady(event) {
this.resultsArray.forEach(result => {
result.gridOption.api = event.api;
result.gridOption.columnApi = event.columnApi;
});
event.api.forEachNode((node) => {
if (node.data?.selected) {
node.setSelected(true);
}
});
}
The resultsArray
holds the data and grid options for each grid. If a user deselects rows in both grids and then clicks on reset, only the last grid is being reset.
For the reset method:
onReset(){
this.resultsArray.forEach(result => {
result.gridOption.api.forEachNode((node) => {
if (node.data?.selected) {
node.setSelected(true);
}
});
});
}
View my stackblitz demo here.
Any suggestions on how to reset every grid, not just the last one?