Pagination

Move through a long list a page at a time: where you are, nearby pages, previous and next, and rows per page.

  • ENG-1284VAT shown twice on EU invoices
  • ENG-1283Wallet button missing on tablets
  • ENG-1282Export to CSV drops the last row
  • ENG-1281Search ignores accents in names
  • ENG-1280Invite email lands in spam

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/pagination

Usage

import { Pagination } from "./ui/uicontext/components/Pagination.ts"
const Message = UiSchema.TaggedEnum({ RequestedPage: { page: Schema.Number } })export const IssuePagination = (h: Html.H<typeof Message.Type>, page: number) =>	Pagination(h, {		page,		pageSize: 20,		total: 1284,		onPage: (next) => Message.RequestedPage({ page: next }),	})

Examples

No total

With total: null the range has no "of", and Next stays on while the server says there's more.

Edge cases

No results, a single page, six-figure counts, and a narrow container.

No results
One page
128,400 rows
320px wide

API reference

Options

Pagination options
NameTypeDefaultDescription
pagerequirednumber—The current page, from 1. The caller keeps it.
pageSizerequirednumber—Rows on a page.
totalrequirednumber | null—How many rows there are, or null when the server doesn't say.
hasMoreboolean—With total: null: there's a page after this one.
nounreadonly [one: string, other: string]—What a row is, for the range: "issue" reads "1–20 of 1,284 issues".
pageSizesnumber[]—The page sizes to offer. Without it there's no size menu.
onPagerequired(page: number) => Message—The page asked for: store it as page and fetch it.
onPageSize(pageSize: number, page: number) => Message—The page size asked for, with the page that keeps the first row in view.
href(page: number) => string—Pages as links, for pages a search engine or a new tab should reach: (page) => \?page=${page}\``.
labelstring"Pagination"Names the navigation landmark; "Pagination" by default.
disabledboolean——
styleStyle—StyleX styles applied after the bar's own.

Source