Pagination allows you to display a subset of data at a time which can be navigated through using the pagination controls.
By default, the pagination is handled on the client. This means you have to give the rows of all pages to the Data Grid. If your dataset is too big, and you want to fetch the pages on demand, you can create a custom action in a custom Toolbar action.
You must opt-in to pagination by setting the initialState.pagination prop to either true
or using a PaginationOptions object on the Data Grid. Doing so will display a
static footer of pagination controls at the bottom of the grid.
To enable custom page sizes, you need to provide a customRange value to the
pagination options. This should be an Array of numbers representing the page sizes to display in the dropdown.
When this is provided, the Data Grid will use the first value in customRange as the initial page size.
To set the default page, you can provide a defaultPage value to the pagination options.
For server-side pagination where the total count is known beforehand, you can
provide a count value to the pagination options.
The Data Grid automatically calculates the total number of pages based on the
count and pageSize values when using client-side pagination.
You can trigger a callback when the page change action is fired by providing a
onPageChange prop to the Data Grid. This will recieve a details object with
the current page number and page size.
This is useful for analytics or tracking page changes.
The pagination options accept the following properties:
| Params | Required | Description |
|---|---|---|
defaultPage | false | The index of the page to display by default. |
count | false | The total number of items in the grid. This is useful for server-side pagination design |
pageSize | false | The initial page size to use when the grid is first rendered. This must be one of the values in customRange. |
customRange | false | An array of custom page sizes to display in the dropdown. This must include the pageSize value. |