Controller
pagination()
Signature
Section titled “Signature”pagination() — returns struct
Available in: controller, model, mapper, migrator, migration, tabledefinition
Category: Pagination Functions
Description
Section titled “Description”Returns a struct with information about the specified paginated query.
The keys that will be included in the struct are currentPage, totalPages and totalRecords.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
handle | string | no | query | The handle given to the query to return pagination information for. |
Examples
Section titled “Examples”// 1. Get pagination info for the default query handle
authors = model("Author").findAll(page=1, perPage=25, order="lastName");
info = pagination();
// info.currentPage -> 1
// info.totalPages -> 4
// info.totalRecords -> 98
// 2. Get pagination info using a named handle (when running multiple paginated queries)
articles = model("Article").findAll(page=2, perPage=10, order="publishedAt DESC", handle="articles");
articleInfo = pagination("articles");
writeOutput("Page " & articleInfo.currentPage & " of " & articleInfo.totalPages);
// 3. Use pagination info to build a simple summary string
products = model("Product").findAll(page=params.page, perPage=20, order="name", handle="products");
info = pagination("products");
writeOutput("Showing page " & info.currentPage & " of " & info.totalPages & " (" & info.totalRecords & " total products)");