假设我有两个域对象,文档和作者
Class Document {
Author author
String title
}
Class Author {
String lastName
String firstName
String toString() {
return lastName + ", " + firstName
}
}
视图 list.gsp 看起来像这样:
<g:sortableColumn property="title" title=... />
<g:sortableCOlumn property="author" title=... />
....
<td>${fieldValue(bean: documentInstance, field: "author"}></td>
<td>${fieldValue(bean: documentInstance, field: "title"}></td>
表中显示的值按预期工作 - 表行将在 documentInstance.title 旁边显示作者为 (lastName, firstName)。
但是,单击 Author 列标题进行排序会导致“文档”按 author.id 排序。
按 author.toString() 或“author.lastName, author.firstName”而不是按 author.id 排序的最方便的方法是什么?
如果可能的话,我宁愿避免回退到 .withCriteria{} - 我有四个不同的列需要此功能,而且看起来会变得混乱。