Search code examples
sortinggrailscollectionsgroovygsp

Sorting collection in groovy


I have code like this in a GSP:

<g:each in="${cifUserInstance.cif?.servicePackage?.transactions?.collect{it.service}}" status="i" var="transaction">

But the resulting data is not sorted; they are displayed randomly. How can I sort the data using the code above?


Solution

  • It's a shot in the dark without seeing what 'transactions' and 'service' look like, but can you try,

    <g:each in="${cifUserInstance.cif?.servicePackage?.transactions?.service.sort()}" status="i" var="transaction">