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

∥☆過路亽.° 提交于 2020-01-03 17:44:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!