# Pagination Navigate between multiple pages of content. ```tsx const users = Array.from({ length: 500 }, (_, i) => ({ id: i + 1, name: faker.person.fullName(), email: faker.internet.email(), country: faker.location.country(), })); const PAGE_SIZE = 10; const [page, setPage] = useState(1); const start = (page - 1) * PAGE_SIZE; const end = start + PAGE_SIZE; const data = users.slice(start, end); return (
{data.map((user) => ( ))}
ID Name Email Country
{user.id} {user.name} {user.email} {user.country}
setPage(event.page)}> {(pagination) => pagination.pages.map((page, index) => page.type === 'page' ? ( {page.value} ) : ( ), ) }
); } ``` ## Page Size ```tsx const users = Array.from({ length: 500 }, (_, i) => ({ id: i + 1, name: faker.person.fullName(), email: faker.internet.email(), country: faker.location.country(), })); const [page, setPage] = useState(1); const [pageSize, setPageSize] = useState(10); const start = (page - 1) * pageSize; const end = start + pageSize; const data = users.slice(start, end); return (
{data.map((user) => ( ))}
ID Name Email Country
{user.id} {user.name} {user.email} {user.country}
setPage(event.page)}> {(pagination) => pagination.pages.map((page, index) => page.type === 'page' ? ( {page.value} ) : ( ), ) }
); } ``` ## Direction ```tsx const users = Array.from({ length: 500 }, (_, i) => ({ id: i + 1, name: faker.person.fullName(), email: faker.internet.email(), country: faker.location.country(), })); const PAGE_SIZE = 10; const [page, setPage] = useState(1); const start = (page - 1) * PAGE_SIZE; const end = start + PAGE_SIZE; const data = users.slice(start, end); return (
{data.map((user) => ( ))}
ID Name Email Country
{user.id} {user.name} {user.email} {user.country}
setPage(event.page)} dir="rtl"> {(pagination) => pagination.pages.map((page, index) => page.type === 'page' ? ( {page.value} ) : ( ), ) }
); } ``` ## Total Count For server-side pagination, your data source may be truncated. Make sure to specify the total records using `count`. ```json { "data": [...], "pagination": { "page": 1, "limit": 10, "count": 500, } } ``` ```tsx ... ``` ## API Reference ### PaginationRoot | Property | Type | Description | | --- | --- | --- | | `ids` | Partial<{ root: string; ellipsis: (index: number) => string; prevTrigger: string; nextTrigger: string; item: (page: number) => string; }> | undefined | The ids of the elements in the accordion. Useful for composition. | | `translations` | IntlTranslations | undefined | Specifies the localized strings that identifies the accessibility elements and their states | | `count` | number | undefined | Total number of data items | | `pageSize` | number | undefined | The controlled number of data items per page | | `defaultPageSize` | number | undefined | The initial number of data items per page when rendered. Use when you don't need to control the page size of the pagination. Default: 10 | | `siblingCount` | number | undefined | Number of pages to show beside active page Default: 1 | | `page` | number | undefined | The controlled active page | | `defaultPage` | number | undefined | The initial active page when rendered. Use when you don't need to control the active page of the pagination. Default: 1 | | `onPageChange` | ((details: PageChangeDetails) => void) | undefined | Called when the page number is changed | | `onPageSizeChange` | ((details: PageSizeChangeDetails) => void) | undefined | Called when the page size is changed | | `type` | "button" | "link" | undefined | The type of the trigger element Default: "button" | | `getPageUrl` | ((details: PageUrlDetails) => string) | undefined | Function to generate href attributes for pagination links. Only used when `type` is set to "link". | | `dir` | "ltr" | "rtl" | undefined | The document's text/writing direction. Default: "ltr" | | `getRootNode` | (() => ShadowRoot | Node | Document) | undefined | A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | | `element` | ((attributes: HTMLAttributes<"nav">) => Element) | undefined | Render the element yourself | ### PaginationRootProvider | Property | Type | Description | | --- | --- | --- | | `value`* | PaginationApi | | | `element` | ((attributes: HTMLAttributes<"nav">) => Element) | undefined | Render the element yourself | ### PaginationRootContext | Property | Type | Description | | --- | --- | --- | | `children`* | (pagination: PaginationApi) => ReactNode | | ### PaginationPrevTrigger | Property | Type | Description | | --- | --- | --- | | `element` | ((attributes: HTMLAttributes<"button">) => Element) | undefined | Render the element yourself | ### PaginationItem | Property | Type | Description | | --- | --- | --- | | `type`* | "page" | | | `value`* | number | | | `element` | ((attributes: HTMLAttributes<"a">) => Element) | undefined | Render the element yourself | ### PaginationEllipsis | Property | Type | Description | | --- | --- | --- | | `index`* | number | | | `element` | ((attributes: HTMLAttributes<"span">) => Element) | undefined | Render the element yourself | ### PaginationNextTrigger | Property | Type | Description | | --- | --- | --- | | `element` | ((attributes: HTMLAttributes<"button">) => Element) | undefined | Render the element yourself |