Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDIT: Found a way to get both! Totally going to use it now</p> <p><a href="http://www.intelligrape.com/blog/tag/pagedresultlist/" rel="nofollow">http://www.intelligrape.com/blog/tag/pagedresultlist/</a></p> <pre><code>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 </code></pre> <p>You will have all the information you need in a nice PagedResultList format!</p> <p>/EDIT</p> <p>Unfortunately I do not know how to get a combination of full results AND max/offset pagination subset in the same call. (Anyone who can enlighten on that?)</p> <p>I can, however, speak to one way I've used with success to get pagination working in general in grails.</p> <pre><code>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 } </code></pre> <p>That's an example of something I'm using to get pagination up and running. As KoK said above, I'm still at a loss for a single atomic statement that gives both results. I realize that my answer is more or less the same as KoK now, sorry, but I think it's worth pointing out that rowCount() in projections is slightly more clear to read, and I don't have comment privileges yet :/</p> <p>Lastly: This is the holy grail (no pun intended) of grails hibernate criteria usage references; bookmark it ;) <a href="http://www.grails.org/doc/1.3.x/ref/Domain%20Classes/createCriteria.html" rel="nofollow">http://www.grails.org/doc/1.3.x/ref/Domain%20Classes/createCriteria.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload