问题
Lets say I have an Issues domain class and it has as a field assignedTo:
String title
String priority
User assignedTo
...
I need to be able to sort on assignedTo. Neither the list.gsp default scaffolding nor the tag it uses, g:sortableColumn, support this. It seems like the g:sortableColumn needs to have both a property field, and a propertyOfProperty field.
Do you know a good way to solve this?
回答1:
Ok, so this appears possible, just missing clarity in the documentation, and searching the web didn't help.
So, one can do property="assignedTo.lastName", i.e.
<g:sortableColumn property="assignedTo.lastName" title="${message(code: 'issue.assignedTo.label', default: 'Assigned To')}" />
回答2:
Ray's solution will work but if assignedTo is a nullable field, any results with assignedTo set as null won't show up in your result list
This grail's solution is a workaround: http://www.grails.org/version/GSP+Tag+-+sortableColumn/2
Of course if it is a required field, or you don't care about not showing results without the assignedTo variable then use property="assignedTo.lastName"
来源:https://stackoverflow.com/questions/7862077/grails-list-gsp-gsortablecolumn-being-able-to-sort-on-associated-domain-obje