sqlgroovypagination

Paging a ArrayList or Result Set


I have a sql.query(myquery, []{Resultset rs -> while(rs.next() { *xml parsing and assigning here*} returning a decently large result set of xml that is then parsed and put in a ArrayList. 2000-10k results. I am populating a html table with these results.. Is there any good way to pass paging params? I can get the page buttons to show up with the correct amount (Ex.2285 Item(s) found so 229 pages show. due wanting 10 per page). But All the items are displayed.

Last time I paged a function with a find all. What I had to do was run that query twice. One with the params passed in and one that found that row count. That method doesn't seem to work and sounds terrible to do since this query is much bigger. Most of the examples online use the Object.list(params) function and that doesn't work for me. I was advised to load the entire result set into memory then page into that but not sure how I would go about doing that.

Any suggestions or examples?


Solution

  • You can use sql.eachRow or sql.rows which takes offset and maxRows as parameters. Here is an example of its usage.