In this blog , we will have a basic idea that how to use LiftWeb’s built -in functionality for Sorting and Pagination .
Lift provides SortedPaginatorSnippet
for sorting of results and PaginatorSnippet
for paging of results .
Suppose you are displaying an item list on web and you want to sort and paginate that list then you have to implement both snippets SortedPaginatorSnippet
and PaginatorSnippet
in your snippet class file .
In SortedPaginatorSnippet , you have to pass type of the elements and type of the fields , which we are going to sort . In PaginatorSnippet , you have to pass type of elements .
After implementing both snippets , now you have to implement header method to specify column , which we are going to sort .
If you are not using sorting , you do not need to implement header method .
Now you have to implement sortOrder method to deal with the database . Here we are using MongoDB , so you have to define sortOrder method in such a way :
For Pagination , you have to override count , itemPerPage and page properties .
count – number of all items you have (here all Measurements)
page – represents current slice
itemPerPage – Number of Items per page
Finally add markup in your HTML :
For Sorting :
For Pagination :
You can found source code on the Knoldus GitHub account here : Login Template using Liftweb and Scala .