I'm trying to get the index of the first row shown.
I need to that so I can restore the scroll position of the grid, but if I use api.getFirstRenderedRow(), I get an index from outside the actually shown grid...
Is there a way to get the first row that is below the header?
thanks!
closest thing is event viewportChanged, the event has the index of the first and last rows rendered.
the default rowBuffer is 10, so 10 rows are rendered above and below the grid. you can set the rowBuffer to zero to get the viewport to be in sync with what you see.
It's pity, the basic function was not provided.
Just posting in case this helps someone I just grabbed the x-y of the header and grabbed the first row using that.
This solution doesn't take into account floating headers and just assumes you only have ag-header as the topmost element (I also have a large row height so picked appropriate rem size.
const headerRect = (this.querySelector('.ag-header').getBoundingClientRect());
const remSize = parseInt(getComputedStyle(document.body).fontSize);
const firstVisible = document.elementFromPoint(headerRect.x+remSize, (headerRect.y + headerRect.height + remSize))
console.log('firstVisible', firstVisible)
const rowIndex = firstVisible.closest('.ag-row').getAttribute('row-index');
console.log('rowIndex', rowIndex)
Most helpful comment
It's pity, the basic function was not provided.