Pagination
A Pagination control has the page buttons for a list that shows one page at a time: previous, the page numbers and next. It always shows the first page, the last page and the pages next to the current one, with "…" for the pages between.


How to page a list:
- Add a
Paginationunder the list. - Give it the number of items and the items on one page.
- In
PageChanged, show the items of the page.
<tb:Pagination name="pages" />
const int pageSize = 10;
var pages = root.Q<Pagination>("pages");
pages.SetItemCount(saves.Count, pageSize);
pages.PageChanged += showPage;
showPage(pages.Page);
void showPage(int page)
{
list.itemsSource = saves.Skip((page - 1) * pageSize).Take(pageSize)
.ToList();
list.Rebuild();
}
| Member | Description |
|---|---|
PageCount (page-count) |
The number of pages (at least 1). When the count goes below the current page, Page moves to the last page. |
Page (page) |
The current page, from 1. A value outside the range is clamped. |
SiblingCount (sibling-count) |
The pages to show on each side of the current page (default 1). |
SetItemCount(itemCount, pageSize) |
Sets PageCount from a number of items, rounded up to full pages. |
PageChanged |
Raised after Page changed, with the new page. Not raised when the value stays the same. |
ShowLabels (show-labels) |
Shows "Previous" and "Next" next to the arrows. Off by default. |
ShowFirstLast (show-first-last) |
Shows a "«" button for the first page and a "»" button for the last page. Off by default. |
PageSizes (page-sizes) |
The page sizes the user can pick, such as 10,25,50. Empty (the default) shows no selector. |
PageSize (page-size) |
The items on one page (default 10). The selector and SetItemCount set it. |
PageSizeChanged |
Raised after PageSize changed, with the new size. |
Pagination.PagesToShow(page, pageCount, siblingCount) |
The page numbers that show, in order, with Pagination.ELLIPSIS (0) for a gap. Use it to make your own page buttons. |
- The previous and next buttons are disabled on the first and the last page.
- With more pages than fit, the control shows the same number of buttons on each page (5 + 2 ×
SiblingCount). The next button does not move, so the user can click it again and again. - A gap of one page shows that page, not "…", because the two take the same room.
- The page buttons are focusable. After a page change, a focus in the page buttons moves to the button of the new current page.
- A focused arrow keeps the focus while it stays enabled. When the change disables it, such as "»" on the last page, the focus moves to the button of the current page.
- The control holds only the page number. It does not own the list or the data.
- The first and last buttons are disabled on the first and the last page, as previous and next are.
- A bare arrow button has a tooltip. With
ShowLabelsthe text says it, and the tooltip is empty. - With
PageSizes, a selector shows after the buttons. A pick setsPageSize. AfterSetItemCount, it also setsPageCountagain for the same number of items, andPagestays in range. - When
PageSizeis not one ofPageSizes, such as 20 with10,25,50, the selector shows it too, before the first larger size: 10, 20, 25, 50.PageSizesdoes not change, and the extra size goes when the user picks another one. - The texts "Previous", "Next", "First page", "Last page" and "Per page" come from
ToolboxText. See Localization.
A pager with all the parts:
<tb:Pagination
name="pages"
show-labels="true"
show-first-last="true"
page-sizes="10,25,50" />
pages.SetItemCount(saves.Count, 10);
pages.PageChanged += showPage;
// The page count is new already; show the items of the page again
pages.PageSizeChanged += _ => showPage(pages.Page);
Tips:
- Call
SetItemCountagain after a filter changes the number of items. The page stays valid. PageChangedis not raised for the first page at the start. Call your handler one time after you connect it, as in the example.- On a narrow screen, set
sibling-count="0"to show fewer buttons.
Styling
| Class | Element |
|---|---|
tb-pagination |
The row: previous, the pages, next. |
tb-pagination__button |
Each button: 24 px high, at least 24 px wide, a border and no background. :hover uses --tb-color-surface-hover; :focus has the accent border. |
tb-pagination__button--current |
The button of the current page, in the accent color. |
tb-pagination__previous, tb-pagination__next |
The "‹" and "›" buttons. |
tb-pagination__first, tb-pagination__last |
The "«" and "»" buttons. |
tb-pagination__sizes |
The page size selector: a label (tb-pagination__sizes-label) and a DropdownField. |
tb-pagination__pages |
The row of page buttons and "…" labels. |
tb-pagination__ellipsis |
A "…" label, 20 px wide at least, in --tb-color-text-muted. |
To center the control and make the buttons round:
.tb-pagination { justify-content: center; }
.tb-pagination .tb-pagination__button { border-radius: 12px; }
The PaginationDemo scene shows a lore book with a chapter on each page, a leaderboard of 250 players with SetItemCount and a jump to the rank of the player, a list of saves with page-sizes and quick saves, and the looks of the pager in a level select.