Pagination
Page links or buttons with ellipses, siblings and first/last controls.
On this page
Examples
Bound page
Buttons report through PageChanged and stay disabled until the page is interactive.
Page: 5
Razor
<div class="flex flex-col items-center gap-3">
<KlyPagination Total="250" PageSize="10" @bind-Page="_page" ShowFirstLast="true" AriaLabel="Results" />
<p class="text-sm text-(--klyroo-text-muted)" data-testid="page-state">Page: @_page</p>
</div>
@code {
private int _page = 5;
}Links
With HrefTemplate every page is a link: it works in static rendering.
Archive page: 1
Razor
@implements IDisposable
@inject NavigationManager Navigation
<div class="flex flex-col items-center gap-3">
<KlyPagination Total="60" PageSize="10" Page="_page" HrefTemplate="@_template" AriaLabel="Archive" Color="KlyColor.Secondary" />
<p class="text-sm text-(--klyroo-text-muted)" data-testid="link-page-state">Archive page: @_page</p>
</div>
@code {
private int _page = 1;
// The document has a <base href>, so a bare "?page=" would resolve against the site root: keep the current path.
private string _template = "?page={page}";
protected override void OnInitialized()
{
_template = new Uri(Navigation.Uri).AbsolutePath + "?page={page}";
Read();
Navigation.LocationChanged += OnLocationChanged;
}
private void OnLocationChanged(object? sender, Microsoft.AspNetCore.Components.Routing.LocationChangedEventArgs e)
{
Read();
_ = InvokeAsync(StateHasChanged);
}
// Links work without interactivity: the page number lives in the query string.
private void Read()
{
var query = System.Web.HttpUtility.ParseQueryString(new Uri(Navigation.Uri).Query);
_page = int.TryParse(query["page"], out var page) ? page : 1;
}
public void Dispose() => Navigation.LocationChanged -= OnLocationChanged;
}Small
Size xs: 24px buttons 4px apart. On a touch screen each keeps its own box as its hit area, because the extended hit area never covers a neighbour.
Razor
<div class="flex flex-col items-center gap-3">
<KlyPagination Total="250" PageSize="10" @bind-Page="_page" Size="KlySize.Xs" ShowFirstLast="true" AriaLabel="Compact pages" data-testid="pagination-xs" />
</div>
@code {
private int _page = 5;
}API
KlyPagination
Page navigation. With an address template every page is a link, so it works in static server rendering.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
AriaLabel |
string |
Accessible name of the landmark. Defaults to Pagination . | |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Color |
KlyColor |
"primary" |
Semantic color of the pagination: a built-in KlyColor or the name of a color you defined. When not set, Color applies, else the default of the component. Values: primary, secondary, success, info, warning, error, neutral. |
HrefTemplate |
string |
Turns pages into links. {page} is replaced by the page number, for example /items?page={page} . The owner of the page reads the number from the URL and passes it as Page . | |
Page (@bind-Page) |
int |
1 |
Current page, starting at 1. |
PageSize |
int |
10 |
Number of items on a page. With Total it gives the number of pages. Defaults to 10. |
ShowControls |
bool |
true |
Previous and next buttons. |
ShowFirstLast |
bool |
false |
Buttons jumping to the first and the last page. |
SiblingCount |
int |
1 |
Pages shown on each side of the current one. |
Size |
KlySize |
KlySize. |
Size of the pagination, from Xs to Xl . When not set, Size applies, else the default of the component. Values: Xs, Sm, Md, Lg, Xl. |
Total |
int |
0 |
Total number of items. The page count is ceil(Total / PageSize) , at least 1. |
Ui |
PaginationUi |
Per-instance class overrides of the slots of the pagination, see PaginationUi . They are merged after the theme and the Class parameter wins on the root slot. |
Ui slots
Ui takes a PaginationUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyPagination , after the theme and the app configuration. |
List |
Classes merged into the list slot of KlyPagination , after the theme and the app configuration. |
Item |
Classes merged into the item slot of KlyPagination , after the theme and the app configuration. |
Page |
Classes merged into the page slot of KlyPagination , after the theme and the app configuration. |
Control |
Classes merged into the control slot of KlyPagination , after the theme and the app configuration. |
Ellipsis |
Classes merged into the ellipsis slot of KlyPagination , after the theme and the app configuration. |
Icon |
Classes merged into the icon slot of KlyPagination , after the theme and the app configuration. |