I have an organization class
class Organization {
hasMany = [member:Members]
}
class Members {
belongsTo = organization
}
I’m printing all the members using
<ol>
<g:each in="${organizationInstance?.members?}" var="m">
<li><g:link controller="members" action="show" id="${m.id}">${m?.encodeAsHTML()}</g:link></li>
</g:each>
</ol>
I want to sort the printing of members so that it would print alphabetically.
any ideas?
First, you need to change somehow your classes in order to have a name for members !
So let’s assume that your classes are:
Then you have two ways of sorting the members in alphabetical order.
First method : you can retrieve all members and then sort them as shown below:
Second Method : You retrieve members directly from GORM in alphabetical order