I want to add pagination in a criteria returned value

grails, pagination

Solution

If you pass the params as first parameter of the `list` method, you get an `PagedResultList` which has the method `getTotalCount()`. With this you could get total number of instances.

params.max = Math.min(params.max?.toInteger() ?: 25, 100)
params.offset = params.offset ? params.offset.toInteger() : 0

def orderInfoCriteria = OrderInfo.createCriteria()
def results = orderInfoCriteria.list(params) { // your criteria code ... }
log.debug "Getting ${results.size()} order infos of ${results.totalCount}"

Read the docs for more information about critera.

Problem

``` params.max = Math.min(params.max ? params.int('max') : 2, 100) orders=OrderInfo.createCriteria().listDistinct() ``` For pagination, we need to pass the params to list eg. `Post.list(params)`. How do I pass it here? I tried but gives an error. We also require total number which I get. But I am not able to set params in ``` orders=OrderInfo.createCriteria().listDistinct() ``` Pls suggest the correct code

Original source