Pagination
Moves through long results one page at a time: ‹ 1 … 4 5 6 … 20 ›. page counts from 1; siblings pages show on each side of it and boundaries at each end. compact shows 4 / 20.
ui.pagination · Category: Navigation · Full reference →


pz.column([ ui.pagination(5, 20, on_page), ui.pagination(1, 3, on_page), ui.pagination(4, 20, on_page, compact=True),], spacing=12, align="center")When to use
Section titled “When to use”- Under a table or a list of search results split into pages.
- When everything fits in one scroll, a Virtual list is simpler.
import pyzed as pzfrom pyzed import ui
pz.column([ ui.pagination(5, 20, on_page), ui.pagination(1, 3, on_page), ui.pagination(4, 20, on_page, compact=True),], spacing=12, align="center")Variants
Section titled “Variants”Options
Section titled “Options”

Code
ui.pagination(2, 5, on_page)

Code
ui.pagination(10, 40, on_page)

siblings=2Code
ui.pagination(10, 40, on_page, siblings=2)

compact=TrueCode
ui.pagination(3, 12, on_page, compact=True)

size="sm"Code
ui.pagination(4, 9, on_page, size="sm")

size="lg"Code
ui.pagination(4, 9, on_page, size="lg")Events
Section titled “Events”Pagination has 1 event of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
| Event | Handler gets | When |
|---|---|---|
on_change |
(page) |
Called with the page that was clicked. |
Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().
Handling the events
Section titled “Handling the events”The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.
class Results(pz.App): def __init__(self): self.page = 1
def go(self, page): # on_change: the page that was clicked, from 1 self.page = page
def view(self): return pz.column([ui.label(f"Results of page {self.page}"), ui.pagination(self.page, 20, self.go)], spacing=8)from dataclasses import dataclass
@dataclassclass Page: number: int
class Results(pz.App): page = 1
def update(self, message): match message: case Page(number): self.page = number
def view(self): return ui.pagination(self.page, 20, Page)from dataclasses import dataclass
@dataclass(frozen=True)class State: page: int = 1
def view(state, set_state): return ui.pagination(state.page, 20, lambda page: set_state(page=page))Properties and API
Section titled “Properties and API”ui.pagination
Section titled “ui.pagination”pagination( page, pages, on_change=None, *, siblings=1, boundaries=1, size='md', compact=False, theme=None,)Page numbers with previous and next arrows (‹ 1 … 4 5 6 … 20 ›). Pages count from 1.
| Property | Default | Description |
|---|---|---|
page |
required | The current page, from 1. |
pages |
required | How many pages there are. |
siblings |
1 |
Pages shown on each side of the current one. |
boundaries |
1 |
Pages always shown at each end. |
size |
"md" |
"sm", "md" or "lg". |
compact |
False |
Shows 4 / 20 between the arrows instead of the numbers. |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_change (events).