I have handler for AGGrid (with server row model) gridReady event handling , where I expected to get count of rows at the end of the handler.
const onGridReadyHandler = useCallback(
async (event: GridReadyEvent) => {
if (serverSide) {
if (serverSide.onGridReady) {
await serverSide.onGridReady(event);
}
...
}
setGridReady(true);
console.log('Displayed rows : ' + event.api.getDisplayedRowCount()); ---> displayed 1 also in the case when rowscount >1
},
.....
);
But in call of console.log I get getDisplayedRowCount() =1 .
When selecting some row , value returned by getDisplayedRowCount() > 1 – as expected .
The question – what can cause of such behavior ? Is there missing something ?
Thanks in advance
2
Answers
It’s possible that the
onGridReady
event is giving you an incorrect row count because you’re using the server-side row model. With this model, rows are only loaded in blocks, so when theonGridReady
event is triggered, only the first block of rows is loaded. This is why thegetDisplayedRowCount()
method only returns 1.To get the total count of all rows, including the ones that haven’t been loaded yet, you can use the
getTotalRowCount()
method from theGridApi
object. This will give you the actual number of rows in your grid.server-side row model here: https://www.ag-grid.com/documentation/javascript/server-side-model/
If you want to have displayed row count, shift your attention to this grid event: onModelUpdated
To get displayed row count in SSRM, you can use this event like that
Here’s a plunker as a reference: https://plnkr.co/edit/pbpDu95BLRlGQWUE?preview