Pagination

Split data into pages and select the page number and item count.

Live preview
Interact with the component to see results here.
View code
HTML
<sy-pagination
  totalitems="123"
  pagesize="10"
  activepage="1"
  pagesizeoptions="10,20,50"
  total
></sy-pagination>

Usage guide

#

Use to browse many items in pages. The app handles actual data requests.

  1. Provide the total count

    totalItems is the item count, not the page count.

  2. Reflect the current page

    activePage starts at 1. Keep query results and page state synchronized.

  3. Fetch again on changes

    Fetch data using the new criteria in pageChanged and pageSizeChanged. The component does not make server requests for you.

Examples

#

Page navigation

Navigate using page numbers and previous/next controls.

View code
HTML
<sy-pagination
  totalitems="123"
  pagesize="10"
  activepage="3"
></sy-pagination>

Items per page

Choose 10, 20, or 50 items. If the current page exceeds the last page, it adjusts to a valid page.

View code
HTML
<sy-pagination
  totalitems="123"
  pagesize="20"
  pagesizeoptions="10,20,50"
  total
></sy-pagination>

Enter a page number

Enter the target page number. Out-of-range values are clamped to the first or last page.

View code
HTML
<sy-pagination
  totalitems="200"
  jumper
  total
></sy-pagination>

Disabled

Disable navigation, page-size changes, and direct page entry together.

View code
HTML
<sy-pagination
  totalitems="123"
  pagesizeoptions="10,20,50"
  jumper
  disabled
></sy-pagination>

When there is one page

The first example keeps the controls; the second hides them with hideonSingle.

View code
HTML
<div style="display:grid;gap:16px;width:100%"><span>Keep controls</span>
  <sy-pagination totalitems="8"></sy-pagination><span>Hide on a single
    page</span>
  <sy-pagination totalitems="8" hideonsingle></sy-pagination>
</div>

Events and payloads

Interact with the component and inspect the latest event name and detail. The code includes subscriptions to events emitted by this component and its children.

View code
HTML
<sy-pagination
  totalitems="123"
  pagesize="10"
  activepage="1"
  pagesizeoptions="10,20,50"
  total
></sy-pagination>
<output id="demo-events" aria-live="polite">Interact with the component to see
  its latest event and payload.</output>

<script type="module">
  const describeResult = value => JSON.stringify(value, (_key, item) => {
    if (item instanceof File) return {
      name: item.name,
      size: item.size,
      type: item.type
    };
    if (item instanceof Element) return `<${item.localName}>`;
    return item;
  }) ?? 'Done';
  for (const name of ["pageChanged", "pageSizeChanged"]) {
    document.addEventListener(name, event => {
      document.querySelector('#demo-events').textContent =
        `${event.target.localName} · ${name}: ${describeResult(event.detail)}`;
    });
  }
</script>

API reference

#

Hover over a name or focus it with the keyboard to see the code. On touch screens, tap the name.

<sy-pagination>

Properties

Attribute / PropertyTypeDefaultDescription
number1Current page number, starting at 1.
booleanfalseBlock user interaction and keyboard focus.
booleanfalseHide controls when all data fits on one page.
booleanfalseShow an input for jumping to a page number.
number10Number of items shown per page.
stringundefinedComma-separated page-size options, such as 10,20,50.
booleanfalseShow the total item count.
number0Total number of data items.

Events

EventDetailDescription
CustomEvent<number>Read the result from the event's detail.
CustomEvent<number>Read the result from the event's detail.