-1

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.

Arpan Solanki
  • 817
  • 1
  • 17
  • 28
  • It works as expected from the `findAll` query without the aforementioned entry in mapping block. How does the gsp look like? – dmahapatro Feb 23 '14 at 16:38

3 Answers3

1

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...

injecteer
  • 20,038
  • 4
  • 45
  • 89
0

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}]
Ima Vafaei
  • 927
  • 1
  • 14
  • 32
0

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

jQuery DataTable rows order

So both the answers above are correct. The issue was actually with jquery data tables.

Community
  • 1
  • 1
Arpan Solanki
  • 817
  • 1
  • 17
  • 28