Grails list.gsp / g: sortableColumn: the ability to sort by related domain objects

Suppose I have a domain class “Questions” and it has assignTo as a field:

String title String priority User assignedTo ... 

I need to be able to sort by destination. Neither by default, nor by default, nor by default, nor by the g method. SortableColumn. It seems that g: sortableColumn should have both a property field and a propertyOfProperty field.

Do you know a good way to solve this problem?

+4
source share
2 answers

Good, so that seems possible, the documentation is simply not clear, and searching the Internet did not help.

So, you can make property = "assignTo.lastName", i.e.

  <g:sortableColumn property="assignedTo.lastName" title="${message(code: 'issue.assignedTo.label', default: 'Assigned To')}" /> 
+1
source

Ray's solution will work, but if assignTo is a nullable field, any results with a null assigned value will not appear in your result list

This grail solution is a workaround: http://www.grails.org/version/GSP+Tag+-+sortableColumn/2

Of course, if this is a required field or you do not need to show results without an assigned variable, then use the property = "assignTo.lastName"

+1
source

All Articles