View as Markdown

Paging

Paging

The pager, page and page size state, page buttons and sizes, keyboard, localized text, the narrow layout, a custom pager, page methods and events, paging with groups, and cursor paging.

paging turns paging on: true for the defaults, or a DataGridPaging object. Pages are a window over the processed (filtered, sorted, grouped) rows; the grid never copies rows per page. paging.pageSize is the page size, 12 by default.

<DataGrid
  data={orders}
  columns={columns}
  paging={{ pageSize: 20, pageSizeOptions: [10, 20, 50, 'all'] }}
  onPageChange={(event) => console.log(event.page, event.pageSize)}
/>

State and events

paging.page is the 1-based page. It is reactive and part of the server render, so a page can render on the server already on page 3. onBeforePageChange can cancel a change with preventDefault(), and onPageChange reports the page, previousPage, pageSize and previousPageSize. Both fire for pager clicks, keys, page size changes and methods, with source telling which.

api.goToPage(page) and api.setPageSize(pageSize) change the page or the page size; api.getPageInfo() returns the page, page size, page count and total row count. Going to a page that does not exist is rejected and raises onError with action: 'page'. Changing the page size keeps the first row of the current page in view and clamps to a valid page.

api.getPageSizeForHeight(height) returns how many whole rows fit in height px after the toolbar, group drop area, header rows, footer aggregate rows and pager. Pass the result to setPageSize to fill a container: with height="auto" the grid, its toolbar and its pager then fit the container exactly. Rows count rowHeight (the estimate when rows are measured); before mount only the header and footer rows are subtracted, and 0 means no row fits.

const fit = () => api.current?.setPageSize(Math.max(1, api.current.getPageSizeForHeight(box.clientHeight)));

The pager

The pager shows first, previous, numbered, next and last buttons. paging.buttonCount (default 8) is how many numbered buttons show at once; the buttons before and after them move to the previous or next set. paging.pageSizeOptions adds a page size dropdown: true for All, 5, 10, 12, 20, or your own list where 'all' shows every row.

The pager is a role="navigation" landmark. Its buttons use roving focus: ←/PageUp and →/PageDown move to the previous or next page, Home or Ctrl+Alt+PageUp to the first and End or Ctrl+Alt+PageDown to the last page, and Enter or Space activates the focused button; on macOS the bindings are ←, →, Home and End. Page changes are announced in a live region ("Page 3 of 12", localeText.pageOf).

Every pager string comes from localeText: pagerLabel, pagerInfo ("{page} of {pageCount} pages"), pagerItems (with plural forms), pageButton, pageSize and the button labels. The pager is a size container: below 480 px it keeps the current page and the arrows and hides the other numbered buttons and the item count.

renderPager(ctx) replaces the pager. The context has the page, pageSize, pageCount, totalRowCount, the resolved pageSizeOptions, goToPage, setPageSize and the defaultPager element to wrap or decorate. The prop is reactive: switching between the built-in and a custom pager on a mounted grid re-renders the pager at once and keeps the current page, as do changes to the other paging options.

Paging

Open demo

The pager with an initial page, page buttons, a page size dropdown, keyboard navigation, localized text, a narrow layout, a custom pager, page methods, the page size that fits a height (getPageSizeForHeight) and cancelable page events.

#
Order
Customer
Country
Product
Amount
21
ORD-10020
Bao Nguyen
Japan
Green tea
$15.73
22
ORD-10021
Hana Sato
Japan
Pour-over kit
$42.00
23
ORD-10022
Elif Kaya
Japan
Grinder
$1,348.05
24
ORD-10023
Dewi Lestari
Germany
Espresso beans
$94.35
25
ORD-10024
Elif Kaya
Portugal
Green tea
$18.50
26
ORD-10025
Farah Aziz
Portugal
Kettle
$220.66
27
ORD-10026
Aiko Tan
Japan
Kettle
$220.66
28
ORD-10027
Chen Wei
Japan
Pour-over kit
$378.00
29
ORD-10028
Jun Park
France
Espresso beans
$47.18
30
ORD-10029
Aiko Tan
Germany
Kettle
$308.27

Use the pager buttons, or focus one and press ←, →, Home or End.

No events yet.

Paging with groups

With grouping, pages count data rows. A page shows the captions and footers of the groups it intersects, so a group that spans two pages has its caption on both, and a collapsed group still occupies its rows of the page. aggregateScope decides whether aggregates cover the current page (the default) or every row; see Aggregates.

Paged groups and aggregate scope

Open demo

400 orders grouped by country and paged 25 data rows at a time; aggregateScope switches the footer and group footers between the current page and every row.

Aggregate scope
Order
Country
Customer
Product
Amount
Country: France - 25 items
ORD-10002
France
Bao Nguyen
Grinder
$857.85
ORD-10006
France
Bao Nguyen
Grinder
$877.20
ORD-10014
France
Aiko Tan
Espresso beans
$111.00
ORD-10022
France
Bao Nguyen
Espresso beans
$210.90
ORD-10023
France
Hana Sato
Grinder
$490.20
ORD-10025
France
Aiko Tan
Pour-over kit
$504.00
ORD-10030
France
Goran Petrov
Green tea
$58.28
ORD-10032
France
Jun Park
Green tea
$37.00
ORD-10046
France
Bao Nguyen
Grinder
$438.60
ORD-10050
France
Ines Duarte
Oolong tea
$75.86
ORD-10052
France
Farah Aziz
Kettle
$246.62
ORD-10059
France
Ines Duarte
Filter beans
$50.40
ORD-10066
France
Dewi Lestari
Kettle
$308.27
ORD-10074
France
Aiko Tan
Filter beans
$11.90
ORD-10080
France
Chen Wei
Grinder
$129.00
ORD-10086
France
Hana Sato
Kettle
$175.23
ORD-10093
France
Jun Park
Green tea
$55.04
ORD-10099
France
Hana Sato
Filter beans
$107.10
ORD-10103
France
Farah Aziz
Green tea
$47.18

Pages count data rows; captions and footers of the groups on a page come along. Change the page and watch the footer.

Remote and cursor paging

With a remote data source the page is part of every read request; see Server paging and the URL. A JSON data source created with paging: { kind: 'cursor' } pages with cursors instead of offsets: the server answers each page with the cursor of the next one, and the next request carries it. The source knows a page's cursor only after reading the page before it, so a jump to a page that was not reached yet is rejected with CursorUnknownError; walk the pages in order.

Cursor paging

Open demo

Remote paging with cursors instead of offsets; each page request carries the cursor the server returned with the previous page.

#
Order
Customer
Country
Product
Amount

Use Next page: each request carries the cursor of the previous response.

No events yet.