Skip to content

Pagination ​

Storybook

Browse the props, controls and all the stories of Pagination in Storybook.

The Pagination component renders the page navigation (previous, page numbers, next), a page size selector and, optionally, the current page and the total number of items. It is a controlled component: it doesn't hold any state and only emits events. The Table component uses it to paginate its rows.

Usage ​

Pagination relies on the Select and PaginationButton components of the registry. Import the all entry point to register them:

tsx
import { useState } from "react";
import { Pagination } from "@tsed/react-formio/molecules/pagination/all";

export function MyPagination() {
  const [pageIndex, setPageIndex] = useState(0);
  const [pageSize, setPageSize] = useState(10);
  const pageCount = 50;

  return (
    <Pagination
      pageIndex={pageIndex}
      pageSize={pageSize}
      pageCount={pageCount}
      canPreviousPage={pageIndex > 0}
      canNextPage={pageIndex < pageCount - 1}
      onPageIndexChange={setPageIndex}
      onClickPreviousPage={() => setPageIndex(pageIndex - 1)}
      onClickNextPage={() => setPageIndex(pageIndex + 1)}
      onPageSizeChange={setPageSize}
    />
  );
}

Or import the modules separately:

tsx
import { Pagination } from "@tsed/react-formio/molecules/pagination/Pagination";
import "@tsed/react-formio/molecules/pagination/PaginationButton";
import "@tsed/react-formio/molecules/forms/select/all";

Props ​

NameTypeDefaultDescription
pageIndexnumberCurrent page index (0-based).
pageCountnumberTotal number of pages.
pageSizenumberCurrent page size, selected in the page size selector.
pageSizesnumber[][10, 25, 50, 100]Page sizes proposed in the page size selector.
canPreviousPagebooleanEnables the "Previous" button.
canNextPagebooleanEnables the "Next" button.
pageOptionsnumber[]When set, displays "Page x of pageOptions.length".
rowCountnumberWhen set, displays the total number of items.
layout"html5" | "react" | "choicesjs"Layout of the page size Select.
i18nFormOptions["i18n"]Translations of the labels (Previous, Next, items per page, Page, Total, items).
classNamestringAdditional CSS classes.
onPageIndexChange(pageIndex: number) => voidCalled with the 0-based index when a page number is clicked.
onClickPreviousPage() => voidCalled when the "Previous" button is clicked.
onClickNextPage() => voidCalled when the "Next" button is clicked.
onPageSizeChange(pageSize: number) => voidCalled when a new page size is selected.

Example ​

Live exampleOpen in Storybook ↗

Override ​

Pagination is registered under the name Pagination, and the buttons it renders under the name PaginationButton. See Registering react components.

tsx
import { registerComponent } from "@tsed/react-formio/registries/components";
import type { PaginationProps } from "@tsed/react-formio/molecules/pagination/Pagination";

function MyPagination(props: PaginationProps) {
  // ...
}

registerComponent("Pagination", MyPagination);

Released under the MIT License.