Skip to content

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 →

PaginationPagination
  • 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 pz
from 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")
Pagination: Few pagesPagination: Few pages
Few pages
Code
ui.pagination(2, 5, on_page)
Pagination: Many pagesPagination: Many pages
Many pages
Code
ui.pagination(10, 40, on_page)
Pagination: siblings=2Pagination: siblings=2
siblings=2
Code
ui.pagination(10, 40, on_page, siblings=2)
Pagination: compact=TruePagination: compact=True
compact=True
Code
ui.pagination(3, 12, on_page, compact=True)
Pagination: size="sm"Pagination: size="sm"
size="sm"
Code
ui.pagination(4, 9, on_page, size="sm")
Pagination: size="lg"Pagination: size="lg"
size="lg"
Code
ui.pagination(4, 9, on_page, size="lg")

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().

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)
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).

Full reference →