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
Few Records
No Records
Without Page Sizes
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
| Variant | What it is |
|---|---|
| default | Range, rows per page, Previous and Next. |
| first or last page | The edge button is disabled. |
| no size | pageSizes 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
| Prop | Type | Default | Description |
|---|---|---|---|
total * | number | — | Total number of records. Required |
page | number | — | Current page, 1-based (controlled) |
defaultPage | number | 1 | Initial page (uncontrolled) |
pageSize | number | — | Rows per page (controlled) |
defaultPageSize | number | 10 | Initial rows per page (uncontrolled) |
pageSizes | readonly number[] | false | [5, 10, 25, 50] | Rows-per-page choices, or false to hide the selector |
onPage | (page: number) => void | none | Called with the new page |
onPageSize | (size: number) => void | none | Called with the new rows per page (the page also resets to 1) |
label | string | "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>
| Kind | Name | Description |
|---|---|---|
| attribute | total | Total number of records. Required |
| attribute | page | Current page, 1-based (controlled) |
| attribute | default-page / defaultPage | Initial page (uncontrolled); default 1 |
| attribute | page-size / pageSize | Rows per page (controlled) |
| attribute | default-page-size / defaultPageSize | Initial rows per page (uncontrolled); default 10 |
| property / JSON attribute | page-sizes / pageSizes | Rows-per-page choices, or false to hide the selector; default [5, 10, 25, 50] |
| attribute | label | Accessible name of the nav landmark; default "Pagination" |
| attribute | default-checked / defaultChecked | |
| property / JSON attribute | default-value / defaultValue | |
| attribute | auto-focus / autoFocus | |
| event | co-page | Called with the new page; default none (React: onPage) |
| event | co-page-size | Called with the new rows per page (the page also resets to 1); default none (React: onPageSize) |