Easygrid icon indicating copy to clipboard operation
Easygrid copied to clipboard

using sortClosure to sort aggregates

Open cyterdan opened this issue 10 years ago • 1 comments

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 {
                    ????
                }
    }

cyterdan avatar Sep 12 '14 11:09 cyterdan

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

tudor-malene avatar Sep 15 '14 20:09 tudor-malene