Sometimes, we need to deal with so much data that presenting them at once to the user is not an option. The reasons are as follows:
It will consume too many resources
It will be slow to render the page to the user
The user is probably not interested in all the data but just a small part of it
This is why we paginate result sets, to make the user's life easier.
In this section, we will see how to paginate a page using another built-in feature from Lift.
We will use the project from the previous recipe. You can duplicate it or modify the same project.
Carry out the following steps to paginate result sets:
In the
Contacts
snippet, add the followingimport
statements:import net.liftweb.http.PaginatorSnippet import net.liftweb.mapper.{MaxRows, StartAt}
Modify the
Contacts
snippet declaration from:class Contacts {
To:
object Contacts extends PaginatorSnippet[Contact]
Add the
count
method.def count = Contact.count
Override the
itemsPerPage
method:override...