newbie2000
newbie2000

Reputation: 83

Scrolling to a row

I need to be able to scroll to the last row at the bottom in reactjs ag-grid, on click of button.

I tried below but its scrolling to the first row instead on the top of the grid.

gridApi.ensureIndexVisible(gridApi.getDisplayedRowCount(), "bottom");

Am I missing something here?

Thanks.

Upvotes: 1

Views: 362

Answers (1)

ViqMontana
ViqMontana

Reputation: 5688

The mistake you're making is scrolling to gridApi.getDisplayedRowCount(), you need to scroll to gridApi.getDisplayedRowCount() - 1, because the row count will always be more than the 0 based index. I.e. if you have 41 rows, the index of the bottom row will be 40, not 41.

Change your code to:

gridApi.ensureIndexVisible(gridApi.getDisplayedRowCount() - 1, "bottom");

Demo

Upvotes: 2

Related Questions