Ray
Ray

Reputation: 6095

grails list.gsp / g:sortableColumn: being able to sort on associated domain objects

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?

Upvotes: 4

Views: 2754

Answers (2)

RasTheDestroyer
RasTheDestroyer

Reputation: 1764

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"

Upvotes: 1

Ray
Ray

Reputation: 6095

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')}" />

Upvotes: 1

Related Questions