How to Refresh Pagination Links via AJAX in Liftweb using Scala

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(
  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>

Now define render method .

def render = {
  "#pagination" #>

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 .

About Ayush Mishra

Ayush is the Sr. Software Consultant @ Knoldus Software LLP. In his 5 years of experience he has become developer with proven experience in architecting and developing web applications. Ayush has a Masters in Computer Application from U.P. Technical University, Ayush is a strong-willed and self-motivated professional who takes deep care in adhering to quality norms within projects. He is capable of managing challenging projects with remarkable deadline sensitivity without compromising code quality. .
This entry was posted in Agile, AJAX, Java, LiftWeb, Scala, Web. Bookmark the permalink.

One Response to How to Refresh Pagination Links via AJAX in Liftweb using Scala

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s