Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Global Navigation

  • Navbar
  • BeianFooter
  • Brand
  • AppLauncher
  • Sidebar
  • NavMenu
  • NavigationMenu
  • Menu
  • Menubar
  • Dock
  • BubbleMenu
  • CardNav
  • FlowingMenu
  • GooeyNav
  • PillNav
  • StaggeredMenu

In-page Navigation

  • RouteTabs
  • Tabs
  • Breadcrumb
  • Pagination
  • Anchor
  • Affix
  • BackTop
  • Stepper
  • Steps
  • PageHeader

Actions and Tools

  • Command
  • ContextMenu
  • Toolbar
  • Accordion
  • Collapsible
  • Link
  • AnimatedThemeToggler

Pagination

pagination

Navigates controlled paged data with page ranges and ellipses.

Usage

Basic usage

Controlled component: holds page status by itself, onPageChange writes back. Click the page number/to switch between previous and next pages.

…More pages
tsx
const [page, setPage] = useState(1);

<Pagination page={page} total={10} onPageChange={setPage} />

Omit both sides

When the total number of pages is large, the outside of both sides of the current page will be automatically folded into ellipses, and the first and last pages will always be displayed.

…More pages…More pages
tsx
<Pagination page={page} total={20} onPageChange={setPage} />

Jump to the first and last pages

showFirstLast Displays the "Go to Home/Last Page" double arrow button.

…More pages…More pages
tsx
<Pagination page={page} total={20} onPageChange={setPage} showFirstLast />

Wider window

siblingCount Controls the number of page numbers displayed on the left and right of the current page, the default is 1.

…More pages…More pages
tsx
<Pagination page={page} total={20} onPageChange={setPage} siblingCount={2} />

Items per page

The switcher renders only when pageSizeOptions and onPageSizeChange are both supplied. If the current page falls outside the new page count after a switch, the component fires onPageChange as well, clamping to the new last page.

5151 items…More pages
tsx
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(20);

<Pagination
  page={page}
  totalItems={5151}
  pageSize={pageSize}
  onPageChange={setPage}
  pageSizeOptions={[20, 50, 100]}
  onPageSizeChange={setPageSize}
  showTotal
/>

Disabled

disabled disables the entire pager and all buttons are unclickable.

…More pages
tsx
<Pagination page={page} total={10} onPageChange={setPage} disabled />

When to use

Use Pagination to move through a list or table when the total page count is known. Use Breadcrumb to communicate hierarchy or Tabs to switch peer content. Import getPaginationRange separately when you need the visible page-number sequence but want to render your own controls.

Import

ts
import { Pagination, getPaginationRange } from "@hulianui/ui"

Props

Pagination is controlled only: store page externally and update it from onPageChange.

NameTypeDefaultDescription
page*number-Controlled current page, starting at 1.
totalnumber-Total number of pages, not items. Mutually exclusive with totalItems; this prop wins when both are supplied.
totalItemsnumber-Total number of items, matching the common data.total API meaning. Used with pageSize to derive pages.
pageSizenumber10Items per page; used only with totalItems.
siblingCountnumber1Visible page numbers on each side of the current page.
showFirstLastbooleanfalseWhether to show first-page and last-page buttons.
showTotalboolean | (totalItems, [from, to]) => ReactNodefalseTotal-items summary on the left. The built-in Chinese format means “N items total.” Requires totalItems and silently renders nothing when only total is provided.
showQuickJumperbooleanfalseWhether to show the page-jump input. Enter and blur submit, clamped to the valid range.
pageSizeOptionsnumber[]-Page-size choices, mirroring el-pagination's page-sizes. The switcher renders only when onPageSizeChange is supplied as well; supplying just one of the two renders nothing.
disabledbooleanfalseWhether all pagination controls are disabled.

Events

EventTypeDescription
onPageChange*(page: number) => voidCalled by page, previous/next, and first/last controls with a value clamped to [1, total].
onPageSizeChange(pageSize: number) => voidCalled with the new page size. The component does not own pageSize, but it does own page repositioning: when totalItems is available and the current page falls outside the new page count, it fires onPageChange as well, clamping to the new last page rather than resetting to page 1.

Example

tsx
function Demo() {
  const [page, setPage] = useState(1);
  return <Pagination page={page} total={20} onPageChange={setPage} />;
}

With first/last controls and a wider page window:

tsx
<Pagination page={page} total={20} onPageChange={setPage} siblingCount={2} showFirstLast />

With an API envelope whose total is an item count:

tsx
// res.data = { list, total: 128 }
<Pagination
  page={page}
  totalItems={res.data.total}
  pageSize={20}
  onPageChange={setPage}
  showTotal
  showQuickJumper
/>

Page-size switcher

tsx
function Demo() {
  const [page, setPage] = useState(1);
  const [pageSize, setPageSize] = useState(20);
  return (
    <Pagination
      page={page}
      totalItems={5151}
      pageSize={pageSize}
      onPageChange={setPage}
      pageSizeOptions={[20, 50, 100]}
      onPageSizeChange={setPageSize}
      showTotal
    />
  );
}

Usage guidelines

  • [[pagination-range-single-gap-fill-not-ellipsis]]: getPaginationRange inserts the missing page number when a gap hides exactly one page. It uses an ellipsis only when the gap is greater than one, avoiding awkward output such as 1 … 3. This follows MUI's usePagination model.
  • The component has no internal page state. If onPageChange does not update page, the controls appear unresponsive.
  • total means pages, unlike the item count commonly named total by APIs. Prefer totalItems with pageSize for API data instead of duplicating Math.ceil at call sites. Passing both props warns in development and uses total.
  • The total semantics are reserved for a breaking correction in 1.0, when the two props can be consolidated. Prefer totalItems in new code.
  • showTotal requires totalItems; page count alone cannot produce an item count, so the summary is omitted rather than throwing.
  • Changing the page size can fire two callbacks for one interaction: onPageSizeChange with the new size, then onPageChange with the clamped page when the current page no longer exists. Write both state updates as usual; React batches them into one render. When only total (page count) is supplied, the new page count cannot be derived, so no onPageChange follows and repositioning is left to you.
  • pageSizeOptions and onPageSizeChange must both be present for the switcher to render: options without a callback means the change has nowhere to go, and a callback without options has nothing to switch between. It renders nothing rather than throwing, matching showTotal.
  • The switcher uses the library Select. It is the same implementation as the switcher in the ProTable footer, so appearance, copy, and accessible name match in both places.
  • Built-in button and jumper labels are Chinese copy: "\u8df3\u5230\u9996\u9875" (“Go to first page”), "\u4e0a\u4e00\u9875" (“Previous page”), "\u4e0b\u4e00\u9875" (“Next page”), "\u8df3\u5230\u672b\u9875" (“Go to last page”), and "\u8df3\u81f3\u7b2c\u51e0\u9875" (“Page to jump to”). Supply a custom showTotal renderer when the built-in Chinese "\u5171 N \u6761" format is not appropriate.

Related

Tabs · Breadcrumb · Anchor · Affix · BackTop · Stepper

Playground

…More pages
<Pagination page={page} total={10} onPageChange={setPage} />
PreviousBreadcrumbNavigationNextAnchor

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Example
    • Usage guidelines
    • Related
  • Playground