skip to Main Content

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


  1. 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 the onGridReady event is triggered, only the first block of rows is loaded. This is why the getDisplayedRowCount() 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 the GridApi object. This will give you the actual number of rows in your grid.

    const onGridReadyHandler = useCallback(
        async (event: GridReadyEvent) => {
            if (serverSide) {
                if (serverSide.onGridReady) {
                    await serverSide.onGridReady(event); 
                }
    
            }
            setGridReady(true);
            console.log('Total rows: ' + event.api.getTotalRowCount());  // returns the actual row count 
        },
    
    );
    

    server-side row model here: https://www.ag-grid.com/documentation/javascript/server-side-model/

    Login or Signup to reply.
  2. If you want to have displayed row count, shift your attention to this grid event: onModelUpdated

    Displayed rows have changed. Triggered after sort, filter or tree expand / collapse events.

    To get displayed row count in SSRM, you can use this event like that

    const onModelUpdated = useCallback((params) => {
      console.log('row count: ', params.api.getDisplayedRowCount());
    }, []);
    

    Reference Picture

    Here’s a plunker as a reference: https://plnkr.co/edit/pbpDu95BLRlGQWUE?preview

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search