Skip to main content

Pagination

Preview
View as Markdown

Page links or buttons for a list that is split into pages.

The context of the root holds the pages to show, each with a type (page or ellipsis), a value and an index. Loop over them with ui:context:

An item without content shows its page number, an ellipsis shows …. With itemTemplate and ellipsisTemplate, the client renders the pages when the page changes without a reload.

Read more about installing Components and Primitives.

Pass the paginator of your list action to paginator, not a TYPO3 pagination: the root works out which pages to show. For links, wrap it in a UrlAwarePaginator with a function that builds the URL of a page, for example with the UriBuilder, which adds the cHash. The root builds the URLs of the pages it shows.

  • Jazz eveningBerlin
  • Farmers marketBerlin
  • Open-air concertHamburg
  • Christmas marketHamburg

Pass your endpoint to fetchUrl, here the same list action with format json, render the root with autoMount="{false}" and mount it yourself with a loadPage function. It loads and shows a page after every page change: pass its signal to the request, so a response of a page that is no longer current is dropped. A click on a link no longer loads its URL: the address bar follows the page, and back and forward change it. For that, the server sends the URL of every page to the client.

With boundaryCount="0" and no ellipsis in the loop, the pagination shows a window of pages around the current one. siblingCount sets its width.

Add firstTrigger and lastTrigger.

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

Provides the pages and labels the navigation. Renders a <nav> element.

NameDescriptionRequiredDefault
paginatorTYPO3\CMS\Core\Pagination\PaginatorInterface
The TYPO3 paginator of the list, e.g. an `ArrayPaginator` or a `QueryResultPaginator`. Wrap it in a `UrlAwarePaginator` for links. It sets the current page and the number of pages.
No
-
countinteger
The total number of items, which sets the number of pages together with `defaultPageSize`. Leave it out with a `paginator`.
No
-
defaultPageinteger
The page that is current when rendered, 1 by default. Leave it out with a `paginator`, which sets it.
No
-
defaultPageSizeinteger
The number of items per page. With a `paginator`, set it to the items per page of the paginator, so the page size in `onPageChange` matches.
No
10
siblingCountinteger
The number of pages shown on each side of the current page.
No
1
boundaryCountinteger
The number of pages always shown at the start and at the end.
No
1
pageUrlsarray
The URL of every page, keyed by the page number starting at 1, for links without a `UrlAwarePaginator`. Leave it out with one. With it, the items and triggers are links to their page.
No
-
fetchUrlstring
The endpoint your client script loads the content of a page from: the library passes it to your `loadPage` and sends no request itself. With links, a click on a page no longer loads it: the URL in the address bar follows the page, and back and forward change it. Buttons have no URL, so the history stays as it is.
No
-
translationsarray
Localized labels: `rootLabel`, `firstTriggerLabel`, `prevTriggerLabel`, `nextTriggerLabel`, `lastTriggerLabel` and `itemLabel`, which takes a `%page%` and a `%totalPages%` placeholder. A client script can pass Zag's `itemLabel` function instead.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
providerstring
The `id` of the `.provider` this root takes its `rootId` and props from.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Goes to one page. Renders an <a> element with a UrlAwarePaginator or pageUrls, a <button> element otherwise.

NameDescriptionRequiredDefault
valueinteger
The page number of the item. Without content, the item shows it. Left out in the `itemTemplate`, where the client sets it.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-pagination-item<uid>
data-indexThe index of the item
data-selectedPresent when selected

Stands for the pages that are left out. Renders a <span> element.

NameDescriptionRequiredDefault
indexinteger
The position of the ellipsis among the pages, the `index` of its entry in `pages`.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-pagination-ellipsis<uid>
data-indexThe index of the item

Holds the item the client clones for a page it renders. Renders a <template> element.

Holds the ellipsis the client clones. Renders a <template> element.

Goes to the first page. Renders an <a> or a <button> element, as the item.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-pagination-first-trigger<uid>
data-disabledPresent when disabled

Goes to the previous page. Renders an <a> or a <button> element, as the item.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-pagination-prev-trigger<uid>
data-disabledPresent when disabled

Goes to the next page. Renders an <a> or a <button> element, as the item.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-pagination-next-trigger<uid>
data-disabledPresent when disabled

Goes to the last page. Renders an <a> or a <button> element, as the item.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-pagination-last-trigger<uid>
data-disabledPresent when disabled
NameTypeDescription
pagenumberThe current page.
countnumberThe total number of data items.
pageSizenumberThe number of data items per page.
totalPagesnumberThe total number of pages.
pagesPagesThe page range. Represented as an array of page numbers (including ellipsis)
previousPagenumber | nullThe previous page.
nextPagenumber | nullThe next page.
pageRangePageRangeThe page range. Represented as an object with `start` and `end` properties.
slice<V>(data: V[]) => V[]Function to slice an array of data based on the current page.
setPageSize(size: number) => voidFunction to set the page size.
setPage(page: number) => voidFunction to set the current page.
goToNextPageVoidFunctionFunction to go to the next page.
goToPrevPageVoidFunctionFunction to go to the previous page.
goToFirstPageVoidFunctionFunction to go to the first page.
goToLastPageVoidFunctionFunction to go to the last page.
getItemState(props: ItemProps) => ItemStateReturns the state of a pagination item