grails - Grails-使用sortableColumn对gsp上的实体进行排序

标签 grails grails-controller

我有以下实体:

class User {

    String name
    String contactName
    String primaryEmail
    String url
    String phoneNumber
    String address
    //..
}

我有gsp显示所有用户的列表,我希望能够通过contactName,name和phoneNumber对用户进行排序,在 Controller 中,我有list()方法,该方法只返回所有用户的列表:
class UserController {
     ...

    def list() {
        [users: User.all]
    }
}

我的gsp是这样的:
<body>
<table>
    <thead>
    <tr>
        <g:sortableColumn property="contactName" title="Bookmaker"/>
        <g:sortableColumn property="name" title="Name"/>
        <g:sortableColumn property="phoneNumber" title="Phone"/>
    </tr>
    </thead>
    <tbody>
    <g:each in="${users}" status="i" var="user">
        <tr>
            <td>${user.contactName}</td>
            <td>${user.name}</td>
            <td>${user.phoneNumber}</td>
        </tr>
    </g:each>
    </tbody>
</table>
</body>

但是,当我单击可排序的列之一时,将发送请求(类似“list?sort = phoneNumber&order = asc”),但响应始终相同。现在在我看来,实际上是对列表进行排序的代码应该由我自己实现。还是我做错了什么?谢谢!

最佳答案

又是你 :)

def list() {
    [users: User.list( params )]
}

关于grails - Grails-使用sortableColumn对gsp上的实体进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24656087/

相关文章:

grails - 如何在Grails 3的编辑 View 中修改ID列的值?

unit-testing - 在grails中执行 Controller 的单元测试时,不能使用grailsApplication.getMetadata.get (“”)

session - 如何在grails中使用 session

grails - 在 Grails 中将 xml 转换为域对象

grails - 在 Controller 中使用快捷方式重定向

grails - Grails设置脚手架下拉框的默认值

grails - 在 View 之间传递记录

unit-testing - Grails 1.3.3:未填充controller.redirectArgs.action

Grails - 如何创建第二个公共(public)域 Controller

unit-testing - 单元测试 Grails Controller 链接