Discussion:
GORM multiple sorting
Vimm
2011-06-08 16:05:02 UTC
Permalink
Will grails' GORM and find methods ever support multiple sorting? There are
so many cases where I'd like to set a default sort but I can't because I'm
limited to a single column. Take my Users table for instance. I'd like
user lists to be sorted by last name, then first name, but instead I'm
forced to choose between the two.

// Why can't I do this?
class Users {
static mapping = {
sort ["lastName", "firstName"]
}
}

// Why can't I do this?
def myUsers = Users.list(sort:["lastName", "firstName"])

This is a somewhat basic database feature that I think would be really,
really helpful to many folks.

--
View this message in context: http://grails.1312388.n4.nabble.com/GORM-multiple-sorting-tp3582932p3582932.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Octavian Covalschi
2011-06-08 16:18:35 UTC
Permalink
You can use multiple 'order' closures using criteria...

Something like this:

def c = Account.createCriteria()
def results = c {
eq("branch", "London")
maxResults(10)
order("holderLastName", "desc")
order("otherField", "asc")
order("otherField2", "desc")
}
Post by Vimm
Will grails' GORM and find methods ever support multiple sorting? There are
so many cases where I'd like to set a default sort but I can't because I'm
limited to a single column. Take my Users table for instance. I'd like
user lists to be sorted by last name, then first name, but instead I'm
forced to choose between the two.
// Why can't I do this?
class Users {
static mapping = {
sort ["lastName", "firstName"]
}
}
// Why can't I do this?
def myUsers = Users.list(sort:["lastName", "firstName"])
This is a somewhat basic database feature that I think would be really,
really helpful to many folks.
--
http://grails.1312388.n4.nabble.com/GORM-multiple-sorting-tp3582932p3582932.html
Sent from the Grails - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Loading...