Pagination

Description

A component to navigate through pages

Pagination allows users to navigate through a large set of data by breaking it into smaller, manageable chunks called pages.

It provides controls to move between pages, jump to specific pages, and see the current position within the total set.

Samples

Basic Pagination

Small Result Set

Large Result Set

API reference

class

Pagination

public sealed class Pagination : ComponentBase<Pagination, HTMLElement>, IBindableComponent<int>

A page-number navigation strip used to walk through pages of results. It reads as a footer under the thing it pages: the controls, then how much there is. A set that fits on one page renders nothing at all, since a lone "1" button beside two greyed chevrons says only that there is nothing to navigate. Call ShowForSinglePage when the strip should hold its place regardless.

Namespace
Tesserae
Inheritance
ComponentBase<Pagination, HTMLElement> → Pagination
Implements
IBindableComponent<int>

Constructors

NameDescription
PaginationInitializes a new instance of this class.
Constructor
Pagination
public Pagination(int totalItems = 0, int pageSize = 10, int currentPage = 1)

Initializes a new instance of this class.

Properties

NameDescription
TotalItemsGets or sets the total items.
PageSizeGets or sets the page size.
CurrentPageGets or sets the current page.
TotalPagesGets or sets the total pages.
MaxPageButtonsGets or sets how many page numbers the strip shows around an ellipsis; minimum 5, default 7. Once a set has more pages than fit, the strip is always this many plus two slots wide.
ShowStatusShows the status.
ShowForSinglePageGets or sets whether the strip renders for a set that fits on a single page. Off by default, which is what keeps a short list from carrying a control that can do nothing.
ShowFirstLastButtonsGets or sets whether the jump-to-first and jump-to-last chevrons render. Off by default: the strip always numbers the first and the last page, so the pair duplicates the two buttons sitting immediately beside them.
Property
Pagination.TotalItems
public int TotalItems { get ; set ; }

Gets or sets the total items.

Property
Pagination.PageSize
public int PageSize { get ; set ; }

Gets or sets the page size.

Property
Pagination.CurrentPage
public int CurrentPage { get ; set ; }

Gets or sets the current page.

Property
Pagination.TotalPages
public int TotalPages { get ; }

Gets or sets the total pages.

Property
Pagination.MaxPageButtons
public int MaxPageButtons { get ; set ; }

Gets or sets how many page numbers the strip shows around an ellipsis; minimum 5, default 7. Once a set has more pages than fit, the strip is always this many plus two slots wide.

Property
Pagination.ShowStatus
public bool ShowStatus { get ; set ; }

Shows the status.

Property
Pagination.ShowForSinglePage
public bool ShowForSinglePage { get ; set ; }

Gets or sets whether the strip renders for a set that fits on a single page. Off by default, which is what keeps a short list from carrying a control that can do nothing.

Property
Pagination.ShowFirstLastButtons
public bool ShowFirstLastButtons { get ; set ; }

Gets or sets whether the jump-to-first and jump-to-last chevrons render. Off by default: the strip always numbers the first and the last page, so the pair duplicates the two buttons sitting immediately beside them.

Methods

NameDescription
SetTotalItemsSets the total items of the component.
SetPageSizeSets the page size of the component.
SetPageSets the page of the component.
SetFormatChanges how the range and the count are written - for another language, or for "1 to 25 of 118".
AsListFooterReturns the component styled as the footer of the list above it - a rule along the top and the padding that separates the controls from the last row.
WithFirstLastButtonsReturns the component configured to render the jump-to-first and jump-to-last chevrons.
AlwaysVisibleReturns the component configured to render for a set that fits on a single page.
AsObservableReturns an observable that tracks the current page number.
SetBoundValueProgrammatically updates the current page as part of a two-way binding.
OnPageChangeRegisters a callback invoked when the page change event fires.
NextConfigures the component to next.
PreviousConfigures the component to previous.
FirstConfigures the component to first.
LastConfigures the component to last.
GetFocusedKeyReads which control the keyboard is on, so the rebuild below can put it back. Without it, paging with the keyboard drops focus to the body and the next Tab starts from the top.
GetPageNumbersThe slots the strip shows, left to right: a page number, or 0 for an ellipsis. Past the point where every page fits, there are always MaxPageButtons + 2 of them and an ellipsis takes a slot the way a number does, so which pages are shown moves as you page and the width of the row never does. An ellipsis always stands for at least two pages.
RenderRenders the component's root HTML element.
Method
Pagination.SetTotalItems
public Pagination SetTotalItems(int totalItems)

Sets the total items of the component.

Method
Pagination.SetPageSize
public Pagination SetPageSize(int pageSize)

Sets the page size of the component.

Method
Pagination.SetPage
public Pagination SetPage(int page, bool raiseEvent = true)

Sets the page of the component.

Method
Pagination.SetFormat
public Pagination SetFormat(Func<int, int, int, string> format)

Changes how the range and the count are written - for another language, or for "1 to 25 of 118".

Method
Pagination.AsListFooter
public Pagination AsListFooter()

Returns the component styled as the footer of the list above it - a rule along the top and the padding that separates the controls from the last row.

Method
Pagination.WithFirstLastButtons
public Pagination WithFirstLastButtons()

Returns the component configured to render the jump-to-first and jump-to-last chevrons.

Method
Pagination.AlwaysVisible
public Pagination AlwaysVisible()

Returns the component configured to render for a set that fits on a single page.

Method
Pagination.AsObservable
public IObservable<int> AsObservable()

Returns an observable that tracks the current page number.

Method
Pagination.SetBoundValue
public void SetBoundValue(int value)

Programmatically updates the current page as part of a two-way binding.

Method
Pagination.OnPageChange
public Pagination OnPageChange(Action<Pagination> onPageChange)

Registers a callback invoked when the page change event fires.

Method
Pagination.Next
public Pagination Next()

Configures the component to next.

Method
Pagination.Previous
public Pagination Previous()

Configures the component to previous.

Method
Pagination.First
public Pagination First()

Configures the component to first.

Method
Pagination.Last
public Pagination Last()

Configures the component to last.

Method
Pagination.GetFocusedKey
private string GetFocusedKey()

Reads which control the keyboard is on, so the rebuild below can put it back. Without it, paging with the keyboard drops focus to the body and the next Tab starts from the top.

Method
Pagination.GetPageNumbers
private IEnumerable<int> GetPageNumbers(int totalPages)

The slots the strip shows, left to right: a page number, or 0 for an ellipsis. Past the point where every page fits, there are always MaxPageButtons + 2 of them and an ellipsis takes a slot the way a number does, so which pages are shown moves as you page and the width of the row never does. An ellipsis always stands for at least two pages.

Method
Pagination.Render
public override HTMLElement Render()

Renders the component's root HTML element.

See also