EDIT: Found a way to get both! Totally going to use it now
http://www.intelligrape.com/blog/tag/pagedresultlist/
If you call createCriteria().list() like this def result=SampleDomain.createCriteria().list(max:params.max, offset:params.offset){ // multiple/complex restrictions maxResults(params.max) firstResult(params.offset) } // Return type is PagedResultList println result println result.totalCount
You will have all the necessary information in a good PagedResultList format!
/ EDIT
Unfortunately, I don't know how to get a combination of the full results and a subset of the max / offset subset in the same call. (Anyone who can enlighten this?)
I can, however, talk to one of the ways in which I used success to get pagination, in general, in the grail.
def numResults = YourDomain.withCriteria() { like(searchField, searchValue) order(sort, order) projections { rowCount() } } def resultList = YourDomain.withCriteria() { like(searchField, searchValue) order(sort, order) maxResults max as int firstResult offset as int }
This is an example of what I use to expand pages. As KoK said above, I'm still at a loss for one atomic statement that gives both results. I understand that my answer is about the same as KoK, now, I'm sorry, but I think it's worth noting that rowCount () in the forecasts reads a little more clearly, and I have no comments yet: /
Finally: this is the holy grail (not intended for puns) of letters referring to the use of hibernation; tag it;) http://www.grails.org/doc/1.3.x/ref/Domain%20Classes/createCriteria.html
Will buck
source share