Grails custom pagination

Custom pagination is rather painless…  create a hibernate query, pass parameters for max number of objects to display.  IBM has great tutorials, found this tutorial, worked like as expected…

IBM Tutorial

Quick Code Snippet

    //setting max to 5 to display
    params.max = Math.min(params.max ?'max') : 5, 100)

    //dummy object to refine list by
    def searchby = SearchBy.findById(
    //creating query
    def query = { eq('searchby', searchby) }

    //populating  list using params for max to display and query    
    def domainInstanceList = Domain.createCriteria().list(params, query)

    //creating total to display
    def domainInstanceTotal = Domain.createCriteria().count(query)

    //setting request objects for list.gsp
    request.domainInstanceList = domainInstanceList
    request.domainInstanceTotal = domainInstanceTotal


One thought on “Grails custom pagination

  1. Amarnath R

    It was a Great Tutorial!

    Very easy to understand

    Thank you very much.

    I got what i expect to get.

    Once again thank you.


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