Paginator
Need to page a data listing? Because mathematics behind pagination can be tricky, Nette\Utils\Paginator will help you.
Installation:
Lets create a paging object and set basic information for it:
Pages are numbered from 1. We can change it using setBase()
:
The object will now provide all the basic information useful in creating a paginator. You can, for example, pass it to a template and use it there.
The paginator will help in formulating the SQL query. The getLength()
and getOffset()
methods return
the values you may use in the LIMIT and OFFSET clauses:
If you need to paginate in reverse order, i.e. page no. 1 corresponds to the highest offset, you may use
getCountdownOffset()
:
An example of use in the application can be found in the cookbook Paginating Database Results.