CLI Overview
Quick Start Guide
wheels info
wheels reload
wheels deps
wheels destroy
wheels watch
wheels generate app
wheels generate app-wizard
wheels generate controller
wheels generate model
wheels generate view
wheels generate property
wheels generate route
wheels generate resource
wheels generate api-resource
wheels generate frontend
wheels generate test
wheels generate snippets
wheels scaffold
wheels db create
wheels db drop
wheels db setup
wheels db reset
wheels db status
wheels db version
wheels db rollback
wheels db seed
wheels db dump
wheels db restore
wheels db shell
wheels db schema
wheels dbmigrate info
wheels dbmigrate latest
wheels dbmigrate up
wheels dbmigrate down
wheels dbmigrate reset
wheels dbmigrate exec
wheels dbmigrate create blank
wheels dbmigrate create table
wheels dbmigrate create column
wheels dbmigrate remove table
wheels test
wheels test run
wheels test coverage
wheels test debug
wheels config list
wheels config set
wheels config env
wheels env
wheels env setup
wheels env list
wheels env switch
wheels environment
wheels console
wheels runner
wheels server
wheels server start
wheels server stop
wheels server restart
wheels server status
wheels server log
wheels server open
wheels plugins
wheels plugins list
wheels plugins install
wheels plugins remove
wheels analyze
wheels analyze code
wheels analyze performance
wheels analyze security
wheels security
wheels security scan
wheels optimize
wheels optimize performance
wheels docs
wheels docs generate
wheels docs serve
wheels ci init
wheels docker init
wheels docker deploy
wheels deploy
wheels deploy audit
wheels deploy exec
wheels deploy hooks
wheels deploy init
wheels deploy lock
wheels deploy logs
wheels deploy proxy
wheels deploy push
wheels deploy rollback
wheels deploy secrets
wheels deploy setup
wheels deploy status
wheels deploy stop
Configuration Management
Creating Commands
Service Architecture
Migrations Guide
Testing Guide
Object Relational Mapping
Creating Records
Reading Records
Updating Records
Deleting Records
Column Statistics
Dynamic Finders
Getting Paginated Data
Associations
Nested Properties
Object Validation
Object Callbacks
Calculated Properties
Transactions
Dirty Records
Soft Delete
Automatic Time Stamps
Using Multiple Data Sources
description: How to create links to other pages in your paginated data in your views.
Displaying Links for Pagination
In the chapter titled Getting Paginated Data, we talked about how to get pages of records from the database (records 11-20, for example). Now we'll show you how to create links to the other pages in your view.
Displaying Paginated Links with the paginationLinks Function
If you have fetched a paginated query in your controller (normally done using findAll() and the page argument), all you have to do to get the page links to show up is this:
#paginationLinks()#
Given that you have only fetched one paginated query in your controller, this will output the links for that query using some sensible defaults.
How simple is that?
Arguments Used for Customization
Simple is good, but sometimes you want a little more control over how the links are displayed. You can control the output of the links in a number of different ways. We'll show you the most important ones here. Please refer to the paginationLinks() documentation for all other uses.
The name Argument
By default, Wheels will create all links with page as the variable that holds the page numbers. So the HTML code will look something like this:
<a href="/main/userlisting?page=1">
<a href="/main/userlisting?page=2">
<a href="/main/userlisting?page=3">
To change page to something else, you use the name argument like so:
#paginationLinks(name="pgnum")#
By the way, perhaps you noticed how Wheels chose to use that hideous question mark in the URL, despite the fact that you have URL rewriting turned on? Because paginationLinks() uses linkTo() in the background, you can easily get rid of it by creating a custom route. You can read more about this in the Routing chapter.
The windowSize Argument
This controls how many links to show around the current page. If you are currently displaying page 6 and pass in windowSize=3
, Wheels will generate links to pages 3, 4, 5, 6, 7, 8, and 9 (three on each side of the current page).
The alwaysShowAnchors Argument
If you pass in true here, it means that no matter where you currently are in the pagination or how many page numbers exist in total, links to the first and last page will always be visible.
Managing More Than One Paginated Query Per Page
Most of the time, you'll only deal with one paginated query per page. But in those cases where you need to get/show more than one paginated query, you can use the handle argument to tell Wheels which query it is that you are referring to.
This argument has to be passed in to both the findAll()
function and the paginationLinks()
function. (You assign a handle name in the findAll()
function and then request the data for it in paginationLinks()
.)
Here is an example of using handles:
In the controller...
users = model("user").findAll(handle="userQuery", page=params.page, perPage=25);
blogs = model("blog").findAll(handle="blogQuery", page=params.page, perPage=25);
In the view...
<ul>
<cfoutput query="users">
<li>#users.name#</li>
</cfoutput>
</ul>
<cfoutput>#paginationLinks(handle="userQuery")#</cfoutput>
<cfoutput query="blog">
#address#<br />
</cfoutput>
<cfoutput>#paginationLinks(handle="blogQuery")#</cfoutput>
That's all you need to know about showing pagination links to get you started. As always, the best way to learn how the view functions work is to just play around with the arguments and see what HTML is produced.