Monday, February 14, 2011

Reverse sort dropdown values in a GSP page

In a GSP page in a Grails application, it is easy to sort values in a dropdown in ascending order. Just pass a closure to sort() call with the name of the attribute to sort by.

  • ${i.name}

  • It is just as easy to sort in descending order. Just provide a sort closure with 2 parameters and return 1 or -1 as in a Comparator.compare() method.
    
    
  • ${i.name}
  • ... or see Tom's post below.