Skip to content

Pagination

A footer for a list that is read a page at a time. It has a page size select, Previous and Next buttons, a window of page numbers, and a total text. It reports skip and take, so it works with a PagedResult.

Decision

When Use
A plain list that loads one page per request Pagination, under the list.
A Paginated Table, a Filtered List, or a Data Table Not the Pagination. They load more as the list scrolls, or from Load more.

Usage

import { createPagination } from './configurationpage?name=myplugin_stolon.js';

var pager = createPagination({ pageSize: 25, onChange: function (v) { load(v.skip, v.take); } });
function load(skip, take) {
    return fetchPage(skip, take).then(function (result) { pager.setResult(result); render(result.Items); });
}

Classes: stolon-pager, stolon-pager-button, stolon-pager-gap. The handle is { element, getValue, setValue, setTotal, setResult, destroy }.

Parts: stolon-pager-number, stolon-pager-pages, stolon-pager-size, stolon-pager-total.

States and Modifiers

  • getValue() returns { page, pageSize, skip, take, total, pageCount }. setResult(result) reads TotalCount (or totalCount) from a PagedResult.
  • The page size is 25 by default, and the select offers 10, 25, 50, and 100 by pageSizes. A page size change returns to page 1, and a page past the last moves to the last.
  • windowSize is the most page numbers shown around the current page, 5 by default. The first and last pages always show.
  • The total reads "{from} to {to} of {total}" by totalText, and "No items." by emptyText when the total is 0. previousText, nextText, pageSizeLabel, navLabel, and pageLabel replace "Previous", "Next", "Page size", "Pagination", and "Page {value}".
  • stolon-pager-button is a page button, and active marks the current page. stolon-pager-gap draws dots between numbers.
  • The buttons are a field tall and the text is the field text size, so they follow size.
  • At 600px and below only the current number shows.
  • size is small, medium (default), or large, and sizes its fields on the size scale.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

createPagination

function createPagination(options?: PaginationOptions): PaginationHandle

A footer for a list that is read a page at a time. It has a page size select, Previous and Next buttons, a window of page numbers, and a total text. It reports skip and take, so it works with a PagedResult of Items and TotalCount.

Option Type What it does
page number first page, counted from 1 (default 1)
pageSize number rows per page (default 25)
total number total rows (default 0)
pageSizes number[] array of numbers in the page size select (default [10, 25, 50, 100])
windowSize number most page numbers shown around the current page (default 5)
previousText string text of the previous button (default 'Previous')
nextText string text of the next button (default 'Next')
pageSizeLabel string label of the page size select (default 'Page size')
navLabel string aria-label of the footer (default 'Pagination')
pageLabel string aria-label of a page number button, where {value} is the number (default 'Page {value}')
totalText string summary where {from}, {to}, and {total} are filled in (default '{from} to {to} of {total}')
emptyText string summary when the total is 0 (default 'No items.')
size 'small' | 'medium' | 'large' 'small', 'medium', or 'large' for its fields (default 'medium')
onChange (value: PaginationValue): void function({ page, pageSize, skip, take, total, pageCount }) called when the user changes the page or the size [optional]
Handle member Type
getValue (): PaginationValue
setValue (next?: { page?: number; pageSize?: number; total?: number; } | null): void
setTotal (total: number | null | undefined): void
setResult (result: { TotalCount?: number; totalCount?: number; } | null | undefined): void
destroy (): void
Type What it is
PaginationValue Where the pager stands, with the skip and take to request that page.
Class What it looks like
stolon-pager Footer for a list read a page at a time, with a total, a page size select, and page buttons
stolon-pager-button One page button or number, filled with the accent when it is the current page
stolon-pager-gap Gap between page numbers, drawn as three dots

Example

Example Code

<!-- title: Pagination -->
<div id="mount"></div>
<script type="module">
const base = await window.__baseReady;
const view = document.getElementById('view');
const mount = document.getElementById('mount');
const note = document.createElement('div');
note.className = 'stolon-status-text';
const pager = base.createPagination({ total: 245, pageSize: 10, page: 4, onChange: (v) => { note.textContent = 'skip ' + v.skip + ', take ' + v.take; } });
mount.appendChild(pager.element);
mount.appendChild(note);
</script>