I am using Groovy SQL for my DB access. Very nice, but I have a need that I can’t find a solution for.
I see pagination supported quite nicely in the Sql class, e.g.:
sql.eachRow('select * from VENDOR', ((pageNumber-1)*pageSize)+1, pageSize) { row ->
...
}
I also see searching/filtering like this:
def rows = sql.rows("select * from PROJECT where name like 'Gra%'")
And finally sorting (and filtering?) like this (using DataSet class):
def vemdpr = new DataSet(sql, 'VENDOR')
def sortedVendorsOfInterest = vendor.
findAll{ it.vendorName like '%Alpha%' }.
sort{ it.vendorName }.reverse() //for desc order, leave off "reverse" for asc
Can anyone tell me how to combine them all to work together? I have a flexigrid that I am showing the table rows and it allows a combination of all these features.
Thanks! Mark
P.S. Barring anyone knowing how to leverage Groovy to do this (my preference), if anyone can tell me how to combine all this into an SQL query I can always just execute the query.
one solution would be to do it as a sql query with parameters:
Taking a look at DataSet sources shows it does not provide paging. It could be added easily by extending DataSet.rows() with the appropriated parameters offset and maxRows and modify underlying call to super.rows(getSql(), getParameters(), offset, maxRows).
— Update —
I’ve raised an issue on Groovy JIRA and created a pull request to solve it on Groovy project which made it into Groovy 2.0 and in Groovy 1.8.7 (not yet released). So now paging is supported at DataSet as well!
See groovy 2.0.0 API: