Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!