Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda