Skip to main content
zerotal

Documentation


Documentation / @zerotal/flow / index / Paginator

Interface: Paginator<T>

Defined in: flow/src/pagination.ts:26

The result of paginating an in-memory array — one page of data plus the surrounding metadata a view needs to render a pager.

The shape intentionally mirrors the ORM query builder's paginator, so a template can consume either interchangeably.

Example

const page = paginate(posts, 2, 10);
page.data;         // the 10 items on page 2
page.from;         // 11
page.hasMorePages; // true if a page 3 exists
page.elements();   // [1, 2, 3, '...', 20]

Type Parameters

T

T

Element type of the paginated array.

Access

data

data: T[]

Defined in: flow/src/pagination.ts:31

The items on the current page (a slice of the input array).

Metadata

total

total: number

Defined in: flow/src/pagination.ts:36

Total item count across all pages.


perPage

perPage: number

Defined in: flow/src/pagination.ts:41

Items per page (the effective, floored value; at least 1).


page

page: number

Defined in: flow/src/pagination.ts:46

Current page (1-based, clamped to a valid range).


lastPage

lastPage: number

Defined in: flow/src/pagination.ts:51

Last page number (>= 1; 1 even when there are no items).


from

from: number

Defined in: flow/src/pagination.ts:56

1-based index of the first item on this page (0 when empty).


to

to: number

Defined in: flow/src/pagination.ts:61

1-based index of the last item on this page (0 when empty).


onFirstPage

onFirstPage: boolean

Defined in: flow/src/pagination.ts:66

True when on page 1.


hasMorePages

hasMorePages: boolean

Defined in: flow/src/pagination.ts:71

True when a further page exists.

elements()

elements(each?): (number | "...")[]

Defined in: flow/src/pagination.ts:81

Page-number window for rendering a numbered pager, with '...' gaps — e.g. [1, '...', 4, 5, 6, '...', 20]. The first and last pages are always included.

Parameters

each?

number

How many page links to show on each side of the current page (default 1).

Returns

(number | "...")[]

A list of page numbers interleaved with '...' for elided ranges.