Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AG Grid: Receiving "invalid row index for ensureIndexVisible" for valid row indexes

I am receiving "invalid row index for ensureIndexVisible" for valid row indexes.

For example:

invalid row index for ensureIndexVisible: 0
invalid row index for ensureIndexVisible: 3

I am not implementing getRowNodeId. Instead, I am letting AG Grid build the IDs, but the problem occurs either way I try it.

Here's the related code in the component:

gridOptions = {
    onGridReady: (params: any) => {
        params.api.sizeColumnsToFit();
    },
    onRowClicked: (params: any) => {
      localStorage.setItem('lastDeveloper', params.node.id.toString());
      this.router.navigate(['developers', params.node.data.id], { state: params.node.data });
    },
    onFirstDataRendered: (params: any) => {
      const lastDeveloperSelected = localStorage.getItem('lastDeveloper');
        if (lastDeveloperSelected) {
          params.api.ensureIndexVisible(lastDeveloperSelected, 'middle');
        }
    }
  }
like image 621
Erik Johnson Avatar asked Sep 15 '25 04:09

Erik Johnson


1 Answers

This appears to have been a type problem, and ensuring the index was a number and not a string made the difference:

params.api.ensureIndexVisible(+lastDeveloperSelected, 'middle');
like image 75
Erik Johnson Avatar answered Sep 17 '25 17:09

Erik Johnson