Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
Getting previous/next row node in a sorted grid

I have a grid with a default sorted on a column and I'm having problems getting the next/previous rows by adding or substracting from the currently selected row ID.

Here's the column with the default sort

{
  headerName: "Created",
  field: "createdOn",
  cellRenderer: (params) => {
    return WebModule.Utils.dateFormat(params.value);
  },
  sort: "desc",
  width: 125
},

And here's my logic to get previous/next row

class ResultModal {

    constructor(params) {
        this.params = params
        let rowIndex = params.rowIndex;
        this.previousRow = params.api.getRowNode(rowIndex - 1);
        this.nextRow = params.api.getRowNode(rowIndex + 1);
        this.result = params.data;
    }
}

I pass the whole ag-grid params object to a modal so I can navigate the grid records from buttons in the modal.

The issue is that if I run the above logic with the 2nd row selected, params.rowIndex is 1, I get nextRow with (1+1) but the actual rowIndex of nextRow will be something like 2245 (I have lots of data in the grid).

So I end up selecting a row burried deep down in the grid instead of the actual 3rd row displayed.

Do I need to use something else than getRowNode when the grid is sorted/filtered ?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I ended up using api.getDisplayedRowAtIndex()

let node = params.api.getSelectedNodes()[0];
let rowIndex = node.rowIndex;
this.previousRow = params.api.getDisplayedRowAtIndex(rowIndex - 1);
this.nextRow = params.api.getDisplayedRowAtIndex(rowIndex + 1);

This really gets the previous and next row regardless of the sort/filter options.

about 4 years ago · Juan Pablo Isaza Denunciar

0

One possible solution might be to use

gridOptions.api.forEachNodeAfterFilterAndSort

which iterates over the rows as they are displayed. Note that the callback passes the RowNode itself and the row-index in the grid.

function forEachNodeAfterFilterAndSort(
    callback: (rowNode: RowNode, index: number) => void
): void;

https://www.ag-grid.com/javascript-data-grid/grid-api/#reference-rowNodes

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda