简体   繁体   English

Groovy:在视图中对列进行排序:列表

[英]Groovy: Sorting Columns in a view: list

I have a Groovy application. 我有一个Groovy应用程序。 I am rendering the view list using the following statement: 我使用以下语句呈现视图列表:

render (view: 'list', model:[reportingInstanceList: reportingInstanceList, reportingInstanceTotal: i, params: params]) 

The list.gsp is as follows: list.gsp如下:

The view is rendered but the default sorting is not working. 呈现视图但默认排序不起作用。

<g:sortableColumn class="tabtitle" property="id" title="Id" titleKey="reporting.id" />
<g:sortableColumn class="tabtitle" property="company" title="Company" titleKey="reporting.company" />

Unfortunately the default sorting (by id, by company, etc) are not working. 不幸的是,默认排序(由id,公司等)不起作用。 Any hint why? 任何暗示为什么?

Thanks a lot in advance. 非常感谢提前。

Luis 路易斯

If you are asking about the sorting/order links at the top of the columns on the list page, the links are hrefs back to the controller and method that was originally used to populate the list. 如果您询问列表页面上列顶部的排序/订单链接,则链接会返回到最初用于填充列表的控制器和方法。 Plus the URLs include parameters for sort and order. 此外,URL还包括排序和订单的参数。 For instance: 例如:

/tracker/bug/searchCurrentUserProject?sort=name&order=asc

The controller method will then need to handle the sort and order values from the link: 然后,控制器方法需要处理链接中的排序和顺序值:

params.sort = params.sort ?: "priority"

params.order = params.order ?: "asc"

And pass them to the database query: 并将它们传递给数据库查询:

def bugList = Bug.createCriteria().list( sort:params.sort, order:params.order, max:params.max, offset:params.offset) { eq "projectId", new Integer (params.projectId) }

您可以在表单中添加两个隐藏字段,使用Javascript动态设置它们并将它们与表单一起发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM