Perform Pagination Manually on List in Grails

Posted By : Varun Sharma | 23-Apr-2014

We have Remote Pagination Plugin in Grails to carryout pagination operations but that is little bit complex to operate with. Also Remote Pagination mostly used in views to paginate through list.

But, what if we need pagination on a list manually like rewuest from mobile app etc. I went through this problem & solved by using the below piece of code.

 

def getPaginatedList(list, max, offset) {
		max = Math.min(max ?: 10, 100)
		offset = offset?:0
                int total = list.size()
		int upperLimit = (offset+max (greterThanEqualto) total?total:offset+max)-1
		return offset (lessThan) total ? list.getAt(offset..upperLimit) : []	
}	

 

Just pass your list, give max count along with offset i.e; from where you want list to begin and this will return you list that is desired.


>Hope it helps !

Varun Sharma [email protected]

http://oodlestechnologies.com/

About Author

Author Image
Varun Sharma

Varun is an experienced Groovy and Grails developer and has worked extensively on designing and developing applications with FaceBook , Linkedin and Twitter integrations using Grails technologies. Varun loves painting and photography.

Request for Proposal

Name is required

Comment is required

Sending message..