Gustavo Damazio
Gustavo Damazio

Reputation: 126

AG GRID - get lines on the current page with pagination and infinite model

I want to know how to get all the nodes or rows that are in the current AG-Grid pagination.

The closest I got to this was this.gridApi.getRenderedNodes(), but it does not bring all the lines from the current page.

Framework website: https://www.ag-grid.com/.

Upvotes: 1

Views: 3785

Answers (2)

restfulhead
restfulhead

Reputation: 444

Here's an example based on ssc-hrep3's answer:

const pageSize = this.gridApi.paginationGetPageSize()
const currentPage = this.gridApi.paginationGetCurrentPage()
const filteredData: MyData[] = []
this.gridApi.forEachNodeAfterFilter((n) => {
  filteredData.push(n.data)
})
const startIndex = currentPage * pageSize
const endIndex = startIndex + pageSize

const pageData = filteredData.slice(startIndex, endIndex)

Upvotes: 1

ssc-hrep3
ssc-hrep3

Reputation: 16099

You can get the data of your table with the API method getModel(). Make sure to use the filtered data. Then, you can use the method paginationGetPageSize() to find out the currently configured page size. Together with paginationGetCurrentPage() you can then extract the subset of rows which are on the current page.

See also the documentation: https://www.ag-grid.com/documentation/javascript/grid-api/

Upvotes: 2

Related Questions