Pagination

A versatile pagination component supporting three modes: client (items already in the DOM — JS shows/hides them), server (renders real <a> links for full-page navigation), and ajax (JS fetches each page and injects the HTML response into a target container).

Client-Side Pagination

All 47 items are rendered server-side. The pagination reads the item count automatically from the target container and shows/hides slices — no database query needed per page. Items must be direct children of the target, or carry data-pagination-item.

1
List Item #1
Client-side pagination — all items are in the DOM
2
List Item #2
Client-side pagination — all items are in the DOM
3
List Item #3
Client-side pagination — all items are in the DOM
4
List Item #4
Client-side pagination — all items are in the DOM
5
List Item #5
Client-side pagination — all items are in the DOM
6
List Item #6
Client-side pagination — all items are in the DOM
7
List Item #7
Client-side pagination — all items are in the DOM
8
List Item #8
Client-side pagination — all items are in the DOM
9
List Item #9
Client-side pagination — all items are in the DOM
10
List Item #10
Client-side pagination — all items are in the DOM
11
List Item #11
Client-side pagination — all items are in the DOM
12
List Item #12
Client-side pagination — all items are in the DOM
13
List Item #13
Client-side pagination — all items are in the DOM
14
List Item #14
Client-side pagination — all items are in the DOM
15
List Item #15
Client-side pagination — all items are in the DOM
16
List Item #16
Client-side pagination — all items are in the DOM
17
List Item #17
Client-side pagination — all items are in the DOM
18
List Item #18
Client-side pagination — all items are in the DOM
19
List Item #19
Client-side pagination — all items are in the DOM
20
List Item #20
Client-side pagination — all items are in the DOM
21
List Item #21
Client-side pagination — all items are in the DOM
22
List Item #22
Client-side pagination — all items are in the DOM
23
List Item #23
Client-side pagination — all items are in the DOM
24
List Item #24
Client-side pagination — all items are in the DOM
25
List Item #25
Client-side pagination — all items are in the DOM
26
List Item #26
Client-side pagination — all items are in the DOM
27
List Item #27
Client-side pagination — all items are in the DOM
28
List Item #28
Client-side pagination — all items are in the DOM
29
List Item #29
Client-side pagination — all items are in the DOM
30
List Item #30
Client-side pagination — all items are in the DOM
31
List Item #31
Client-side pagination — all items are in the DOM
32
List Item #32
Client-side pagination — all items are in the DOM
33
List Item #33
Client-side pagination — all items are in the DOM
34
List Item #34
Client-side pagination — all items are in the DOM
35
List Item #35
Client-side pagination — all items are in the DOM
36
List Item #36
Client-side pagination — all items are in the DOM
37
List Item #37
Client-side pagination — all items are in the DOM
38
List Item #38
Client-side pagination — all items are in the DOM
39
List Item #39
Client-side pagination — all items are in the DOM
40
List Item #40
Client-side pagination — all items are in the DOM
41
List Item #41
Client-side pagination — all items are in the DOM
42
List Item #42
Client-side pagination — all items are in the DOM
43
List Item #43
Client-side pagination — all items are in the DOM
44
List Item #44
Client-side pagination — all items are in the DOM
45
List Item #45
Client-side pagination — all items are in the DOM
46
List Item #46
Client-side pagination — all items are in the DOM
47
List Item #47
Client-side pagination — all items are in the DOM

Server-Side Pagination

PHP renders <a href="…"> links for each page. The controller passes total, perPage, and currentPage from the database query, and the component builds the correct button set. Full-page reload on navigation (standard web behaviour).

AJAX Pagination

On each page change, JS calls the configured URL (with {page} and {perPage} tokens), then injects the HTML response into the target container. The endpoint may return plain HTML or a JSON object { html, total } to also update the total count. A loading state is applied to the target during fetch.

Loading first page…

Variants — Compact, Large, Alignment

Compact

1
Record #1
2
Record #2
3
Record #3
4
Record #4
5
Record #5
6
Record #6
7
Record #7
8
Record #8
9
Record #9
10
Record #10
11
Record #11
12
Record #12
13
Record #13
14
Record #14
15
Record #15
16
Record #16
17
Record #17
18
Record #18

Large, left-aligned, with first/last jump buttons

Label Position

The ->labelPosition() method controls where the "Showing X–Y of Z" label appears relative to the page buttons. Accepted values: 'left' (default), 'right', 'above', 'below', and 'none'. Calling this method automatically shows the label — no separate ->showInfo() call is needed.

above — label row above the buttons

below — label row below the buttons

right — label on the right, controls centred

none — label hidden, controls centred

Label Position

The ->labelPosition() method controls where the "Showing X–Y of Z" label appears relative to the page buttons. Accepted values: 'left' (default), 'right', 'above', 'below', and 'none'. Calling this method automatically shows the label; no separate ->showInfo() call is needed.

above — label row above the buttons

below — label row below the buttons

right — label on the right side (controls centred)

none — label hidden, controls centred

Interact with the client or AJAX pager above to see events here…
PHP

PHP PHP Methods (Fluent)

Method / PropertyParametersDescription
$m->pagination($id)PaginationCreate a new pagination component.
->total($n)selfTotal number of items. In client mode, leave 0 for auto-count.
->perPage($n)selfItems per page. Default: 10.
->currentPage($n)selfCurrent page (1-based). Default: 1.
->target($id)selfID of the container whose children are paginated (client/ajax).
->mode($m)self'client' (default), 'server', or 'ajax'.
->url($template)selfURL template. Tokens: {page}, {perPage}. Required for server mode; optional for ajax auto-fetch.
->showInfo()selfShow "Showing X\u2013Y of Z" info text at the left. Default: false.
->labelPosition($pos)selfSet info label position and show it. 'left' (default), 'right', 'above', 'below', 'none'. Preferred over ->showInfo() when position matters.
->showSizeSelector($sizes)selfShow a per-page size selector. E.g. [10, 25, 50].
->align($a)selfAlignment: 'center' (default), 'left', 'right'.
->maxButtons($n)selfMax page buttons including ellipsis. Default: 7.
->showFirstLast()selfShow « (first) and » (last) jump buttons. Default: false.
->compact()selfUse smaller buttons.
->large()selfUse larger buttons.
->autoLoad()selfAjax mode: fetch page 1 automatically on init. Default: false.

JS JS Methods

Method / PropertyParametersDescription
m.pagination(id)object|nullGet or create a pagination instance.
p.goTo(n)Navigate to page n.
p.next() / p.prev() / p.first() / p.last()Navigate relative pages.
p.setTotal(n)Update total item count and re-render controls.
p.setPerPage(n)Change per-page size and navigate to page 1.
p.getState()objectReturns { page, perPage, total, totalPages, offset, limit }.
p.refresh()Re-discover items in target (client mode) and re-scan external triggers.
p.elementHTMLElementThe underlying <nav> DOM element.

EVENT Events

Event NameDetailDescription
m:pagination:change{ page, perPage, total, totalPages, offset, limit }Fired on every page or per-page change. Use offset and limit in AJAX calls for SQL-style slicing.
m:pagination:loaded{ page, perPage, url }Fired after ajax auto-fetch completes and HTML has been injected.