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]
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
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.