Page Breaks in Grails

I want to add some pagination elements to a grails application. I have a list action and in it I did this:

if(!params.max){ params.max = 3 } def query = Profile.where { userType == "F" } def freelancers = query.list(sort:"firstName", max:params.max) if(freelancers) { def freelancersCount = query.count() return[freelancer:freelancers, fCount:freelancersCount] } else { response.sendError(404) } 

in gsp I wrote this:

 <div id="paginate"> <g:paginate controller="freelancers" action="list" total="${fCount}"/> </div> 

everything is fine, I have 5 objects in my db, and I see only 3 when I open the gsp page in the browser, but when I click Next to open another object 2, I see the same 3. what is wrong and what I have to do?

+6
source share
2 answers

You need to pass the offset to your list call:

 def freelancers = query.list(sort:"firstName", offset:params.offset, max:params.max) 
+8
source

1) If you are using a Criteria request, then:

  params.max = Math.min(max ?: 10, 100) Integer offset = params.offset as Integer ?: 0 List userInstanceList = User.createCriteria().list(max:params.max,offset:offset) { or { ilike('name', "%${name}%") ilike('email', "%${email}%") } order('dateCreated', 'desc') } 

2) If you are using a GORM request, then:

  params.max = Math.min(max ?: 10, 100) Integer offset = params.offset as Integer ?: 0 List<User> userList=User.list(max:params.max,offset:offset) 
+1
source

Source: https://habr.com/ru/post/920602/


All Articles