Hikaru Shindo
Hikaru Shindo

Reputation: 2913

Max and offset in Grails?

I have some list data and I want to do pagination. But I don't understand how to use 'max'. Here is my simple query code,

def users = User.where{
  roles {
     id in roles.id 
  }
}.list(max: 1)
println users

And I didn't understand what is offset. If I want show 5 data per page, What is my offset should be ?

Upvotes: 5

Views: 3059

Answers (1)

Koloritnij
Koloritnij

Reputation: 1217

Write like this one, I took it from official docs:

def users = User.createCriteria().list (max: 10, offset: 10) {
    roles {
        'in'('id', roles*.id) 
    }
}

link to createCriteria docs You can take on controller params.offset and params.max and use it in those criteria. For example:

def users = User.createCriteria().list (max: params.max, offset: param.offset) {...}

I think you can add some links under list of elements with offset what you want. Good luck :)

Upvotes: 2

Related Questions