Easygrid
Easygrid copied to clipboard
using sortClosure to sort aggregates
Hi,
How can i make column meanAge sortable in the following grid :
def supGrid = {
domainClass Group
columns = {
id
meanAge
value {
//return the mean age of persons in a group
Group g -> g.persons.sum{ it.person.age}/ g.persons.size()
}
sortClosure {
????
}
}
Hi,
This is a little tricky. You have to run the sort in the database.
The easiest option is to create a derived property: See: http://www.grails.org/doc/latest/guide/GORM.html#derivedProperties
Another option is to use initialCriteria
and transformData
see :
https://github.com/tudor-malene/Easygrid/blob/master/test/integration/org/grails/plugin/easygrid/GormDatasourceServiceSpec.groovy#L527