我有一个 Groovy 应用程序。我正在使用以下语句呈现 View 列表:
render (view: 'list', model:[reportingInstanceList: reportingInstanceList, reportingInstanceTotal: i, params: params])
list.gsp 如下:
View 已呈现,但默认排序不起作用。
<g:sortableColumn class="tabtitle" property="id" title="Id" titleKey="reporting.id" />
<g:sortableColumn class="tabtitle" property="company" title="Company" titleKey="reporting.company" />
不幸的是,默认排序(按 id、按公司等)不起作用。
任何提示为什么?
非常感谢。
路易斯
最佳答案
如果您要询问列表页面上列顶部的排序/排序链接,这些链接是指向最初用于填充列表的 Controller 和方法的 href。另外,URL 包括用于排序和排序的参数。例如:/tracker/bug/searchCurrentUserProject?sort=name&order=asc
然后 Controller 方法需要处理来自链接的排序和排序值:
params.sort = params.sort ?: "priority"
params.order = params.order ?: "asc"
并将它们传递给数据库查询:
def bugList = Bug.createCriteria().list(
sort:params.sort,
order:params.order,
max:params.max,
offset:params.offset) {
eq "projectId", new Integer (params.projectId)
}
关于grails - Groovy:对 View 中的列进行排序:列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1929245/