当列是类的排序集时 Groovy 表排序
我有一个列出了几个承包商对象的视图。最后一列来自地址,它是承包商对象中的排序集。我试图对这些列进行排序,但出现一个异常,即属性地址未在类 Contractors 中定义。我需要在控制器中以不同的方式处理排序集吗?
<table width="100%">
<thead>
<tr>
<th></th>
<g:sortableColumn property="status" title="${message(code: 'contractor.status.label', default: 'Status')}" params="[statuses:statuses,name:name,nameOperator:nameOperator ?: 'CONTAINS']"/>
<g:sortableColumn property="contractorName" title="${message(code: 'contractor.contractorName.label', default: 'Name')}" params="[statuses:statuses,name:name,nameOperator:nameOperator ?: 'CONTAINS']"/>
<g:sortableColumn property="addresses.address" title='Address' params="[statuses:statuses,name:name,nameOperator:nameOperator ?: 'CONTAINS']"/>
</tr>
</thead>
<tbody>
<g:each in="${contractorList}" status="i" var="contractor">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<td>
<g:link action="show" id="${contractor.id}">show</g:link>
|
<g:link action="edit" id="${contractor.id}">edit</g:link>
</td>
<td>${contractor.status}</td>
<td>${contractor.contractorName}</td>
<td>${contractor?.addresses?.address}</td>
</tr>
</g:each>
</tbody>
</table>
控制器中的逻辑:
order(params.sort, params.order)
我对 groovy/grails 非常陌生,任何帮助将不胜感激,谢谢!
I have a a view that lists several contractor objects. The last column is from addresses which is a sorted set in the contractor object. I am trying to sort those columns and I get an exception that the property addresses is not defined in class Contractors. Do I need to handle the sorted set differently in the controller?
<table width="100%">
<thead>
<tr>
<th></th>
<g:sortableColumn property="status" title="${message(code: 'contractor.status.label', default: 'Status')}" params="[statuses:statuses,name:name,nameOperator:nameOperator ?: 'CONTAINS']"/>
<g:sortableColumn property="contractorName" title="${message(code: 'contractor.contractorName.label', default: 'Name')}" params="[statuses:statuses,name:name,nameOperator:nameOperator ?: 'CONTAINS']"/>
<g:sortableColumn property="addresses.address" title='Address' params="[statuses:statuses,name:name,nameOperator:nameOperator ?: 'CONTAINS']"/>
</tr>
</thead>
<tbody>
<g:each in="${contractorList}" status="i" var="contractor">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<td>
<g:link action="show" id="${contractor.id}">show</g:link>
|
<g:link action="edit" id="${contractor.id}">edit</g:link>
</td>
<td>${contractor.status}</td>
<td>${contractor.contractorName}</td>
<td>${contractor?.addresses?.address}</td>
</tr>
</g:each>
</tbody>
</table>
The logic in the controller:
order(params.sort, params.order)
I am very new to groovy/grails any help would be appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定是否有任何现成可用的东西,但这是我解决类似问题的方法。基本上我必须拦截排序参数并进行自己的排序。:
--- 其中 sortByState 是这样的:
I am not sure if there is anything availabel out of the box for this but here is how I solved my similar issue. Basically I had to interecept sort param and do my own sorting.:
--- where sortByState is this: