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.
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
Client-side pagination — all items are in the DOM
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.
Variants — Compact, Large, Alignment
Compact
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
PHP PHP Methods (Fluent)
| Method / Property | Parameters | Description |
|---|---|---|
$m->pagination($id) | Pagination | Create a new pagination component. |
->total($n) | self | Total number of items. In client mode, leave 0 for auto-count. |
->perPage($n) | self | Items per page. Default: 10. |
->currentPage($n) | self | Current page (1-based). Default: 1. |
->target($id) | self | ID of the container whose children are paginated (client/ajax). |
->mode($m) | self | 'client' (default), 'server', or 'ajax'. |
->url($template) | self | URL template. Tokens: {page}, {perPage}. Required for server mode; optional for ajax auto-fetch. |
->showInfo() | self | Show "Showing X\u2013Y of Z" info text at the left. Default: false. |
->labelPosition($pos) | self | Set info label position and show it. 'left' (default), 'right', 'above', 'below', 'none'. Preferred over ->showInfo() when position matters. |
->showSizeSelector($sizes) | self | Show a per-page size selector. E.g. [10, 25, 50]. |
->align($a) | self | Alignment: 'center' (default), 'left', 'right'. |
->maxButtons($n) | self | Max page buttons including ellipsis. Default: 7. |
->showFirstLast() | self | Show « (first) and » (last) jump buttons. Default: false. |
->compact() | self | Use smaller buttons. |
->large() | self | Use larger buttons. |
->autoLoad() | self | Ajax mode: fetch page 1 automatically on init. Default: false. |
JS JS Methods
| Method / Property | Parameters | Description |
|---|---|---|
m.pagination(id) | object|null | Get 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() | object | Returns { page, perPage, total, totalPages, offset, limit }. |
p.refresh() | | Re-discover items in target (client mode) and re-scan external triggers. |
p.element | HTMLElement | The underlying <nav> DOM element. |
EVENT Events
| Event Name | Detail | Description |
|---|---|---|
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. |