In our previous blog , we explained about using Pagination in Lift using Scala . But If you render a page via AJAX , pagination link would not be refreshed until we reload the page .
In this blog , we will have a basic idea that how to refresh pagination via AJAX .
Suppose you are displaying an item list on web and you want to paginate that list then you have to implement PaginatorSnippet in your snippet class file .
class Remindersnips extends PaginatorSnippet[Reminder] {
...................
}
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
val user = User.findCurrentUser
override def count = Reminder.findAllNotes(
user.userIdAsString).size
override def itemsPerPage = 5
override def page = Reminder.findAll((("owner" -> user.userIdAsString)), Skip((curPage * itemsPerPage)), Limit(itemsPerPage))
Now define RequestVar holders for Pagination
object refreshPagination extends RequestVar(renderPagination)
private def renderPagination = SHtml.memoize {
"#pagination" #> (<div>
<lift:remindersnips.paginate>
<p>
<nav:records></nav:records>
</p>
<nav:first></nav:first>
|<nav:prev></nav:prev>
|<nav:allpages></nav:allpages>
|<nav:next></nav:next>
|<nav:last></nav:last>
</lift:remindersnips.paginate>
</div>)
}
Now define render method .
def render = {
"#pagination" #> refreshPagination.is
}
Finally add below markup in your HTML file .
<div id="pagination"></div>
Source Code : You can found source code on the Knoldus GitHub account here : Login Template using Liftweb and Scala .






Reblogged this on Sutoprise Avenue, A SutoCom Source.