Why aren't you using the dynamic finders
?
Roll.findAllByUserid( uid, [ sort:"rollDate", order: 'desc'] )
should work.
The findAll( Map, Closure )
method appeared not a long time ago, perhaps it was not tested well...
Pergunta
I have domain object named Roll and on the list page i want to show the user all the Roll objects iterating through a list, sorted by entry date.
Here is the code i am using
[rollList: Roll.findAll(sort:"rollDate"){userid==uid}]
rollDate is a field inside the Roll object with data type java.util.Date
Any suggestion on why the output is not sorted by rollDate. When i iterate through the rollList on the gsp page it is not sorted.
Also, on the Roll domain object i have even put this code, but it's still not sorting.
static mapping = {
sort "rollDate"
}
Thank you.
Solução
Why aren't you using the dynamic finders
?
Roll.findAllByUserid( uid, [ sort:"rollDate", order: 'desc'] )
should work.
The findAll( Map, Closure )
method appeared not a long time ago, perhaps it was not tested well...
Outras dicas
You might need to use order in your query as well, then add order to it
[rollList: Roll.findAll(sort:"rollDate", order: 'desc'){userid==uid}]
After trying both the solutions mentioned it still didn't work. So i thought something might be wrong on the front end. While researching more i found that since i was using jquery data tables it used to re order the sorting. The solutions i found was here
So both the answers above are correct. The issue was actually with jquery data tables.