jayanthCoder
jayanthCoder

Reputation: 873

Row count in aggrid with pagination

I am using aggrid with pagination(client side).

I need to get the count of rows present in current page.

When i use the below apis it always gives me count of all rows present in all pages.

gridApi.paginationGetRowCount()

gridApi.getDisplayedRowCount()

gridApi.paginationProxy.masterRowCount

Upvotes: 3

Views: 6240

Answers (1)

NearHuscarl
NearHuscarl

Reputation: 81833

The one you need is GridApi.paginationGetPageSize().

  • GridApi.paginationGetRowCount() returns total number of rows in all pages.
  • GridApi.getDisplayedRowCount() returns total number of rows in all pages, plus all expanded rows (when using Row Grouping or Master Detail).
  • GridApi.paginationProxy is a private property and should not be used.

If you want to get the number of rows in current page. You can calculate the startResult and endResult of that page yourself. The number of rows in the page is endResult - startResult + 1

const printPagination = () => {
  const currentPage = gridApi.paginationGetCurrentPage();
  const totalPage = gridApi.paginationGetTotalPages();
  const totalResults = gridApi.paginationGetRowCount();
  const pageSize = gridApi.paginationGetPageSize();
  const startResult = currentPage * pageSize + 1;
  const endResult = Math.min(startResult + pageSize - 1, totalResults);

  console.log();
  console.log("Page size:", pageSize);
  console.log("Current page:", currentPage);
  console.log("Total pages:", totalPage);
  console.log("Total results:", totalResults);
  console.log("Start-end:", startResult, endResult);
  console.log("Number of rows in this page:", endResult - startResult + 1);
};

Live Example

The live example below uses React but it should be trivial to convert that code to angular

Edit AgGrid Number Of Rows In Current Page

Upvotes: 3

Related Questions