Skip to main content

Pagination

BasicData display<co-pagination>

Pagination shows the record range and lets staff change rows per page and move between pages.

import { Pagination } from 'health-components';

Examples​

Showcase​

Storybook

Few Records​

Storybook

No Records​

Storybook

Without Page Sizes​

Storybook

Usage​

<Pagination total={248} page={page} pageSize={size} onPage={setPage} onPageSize={setSize} />

When to use​

  • Under any paged table.

When not to use​

  • Infinite scroll on phones.

Variants and states​

VariantWhat it is
defaultRange, rows per page, Previous and Next.
first or last pageThe edge button is disabled.
no sizepageSizes false hides the select.

Accessibility​

  • nav landmark named Pagination; the page info is aria-live.

Do and don't​

  • Do: "Showing 11-20 of 248".
  • Don't: Page number lists longer than the table.

Props​

PropTypeDefaultDescription
total *number—Total number of records. Required
pagenumber—Current page, 1-based (controlled)
defaultPagenumber1Initial page (uncontrolled)
pageSizenumber—Rows per page (controlled)
defaultPageSizenumber10Initial rows per page (uncontrolled)
pageSizesreadonly number[] | false[5, 10, 25, 50]Rows-per-page choices, or false to hide the selector
onPage(page: number) => voidnoneCalled with the new page
onPageSize(size: number) => voidnoneCalled with the new rows per page (the page also resets to 1)
labelstring"Pagination"Accessible name of the nav landmark

Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-pagination>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-pagination total="…" page="…" [pageSizes]="pageSizes" (co-page)="onPage($event.detail)"></co-pagination>
KindNameDescription
attributetotalTotal number of records. Required
attributepageCurrent page, 1-based (controlled)
attributedefault-page / defaultPageInitial page (uncontrolled); default 1
attributepage-size / pageSizeRows per page (controlled)
attributedefault-page-size / defaultPageSizeInitial rows per page (uncontrolled); default 10
property / JSON attributepage-sizes / pageSizesRows-per-page choices, or false to hide the selector; default [5, 10, 25, 50]
attributelabelAccessible name of the nav landmark; default "Pagination"
attributedefault-checked / defaultChecked
property / JSON attributedefault-value / defaultValue
attributeauto-focus / autoFocus
eventco-pageCalled with the new page; default none (React: onPage)
eventco-page-sizeCalled with the new rows per page (the page also resets to 1); default none (React: onPageSize)