javascript - 如何对包含 Controller 传递的sql行的gsp中的表进行排序

标签 javascript grails groovy gsp

我正在使用 Grails 的 sortablecolumn 功能对 gsp 中的表列进行动态排序。我有 3 个表,其中包含由 Controller 代码传递的 sql 行。

我的 Controller 代码是:

def ABC{
def A= AService.a()
def B=BService.b()
def C=CService.b()
render(view:list,model:[A:A,B:B,C:C])
}

AService、BService 和 CService 包含 sql 代码并返回行。

我的list.gsp代码是:

<body>
        <div class="body">
            <h1>ABC</h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="list">
                <table>
                <thead>
                    <tr>
                        <g:sortableColumn property="name" title="NAME" />
                        <g:sortableColumn property="id" title="ID" />


                        <th>&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                <g:each in="${A}" status="i" var="thisRecord">
                    <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                        <td>${thisRecord.name}</td>
                        <td>${thisRecord.id}</td>


                    </tr>
                </g:each>
                </tbody>
                </table>
                </div>
        </div>
    </body>
</html>

还有另外两个表。每当我单击前端的列时,表格都无法正确排序。有不对的地方请指正。

最佳答案

排序通常发生在服务器端。因此,排序参数被传递到 Controller 中,查询函数采用排序参数对数据进行排序。 View 层不进行排序。您的 Controller 预计会返回排序后的数据。在您的示例中,您需要添加代码以在通过 render 方法返回数据之前对数据进行排序。

关于javascript - 如何对包含 Controller 传递的sql行的gsp中的表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28205173/

相关文章:

grails - 用参数解析消息

grails - Grails 2.4.3,部署 war 中的 “resource is not available”

html - 为什么我的 CSS 样式表不能在 Grails 中链接?

java - 使用 groovy 中的 map 编写 Excel

javascript - 如何在 Three.js 中创建无限的地板(天际线)?

javascript - setState 不会导致渲染 React Native

javascript - Cakephp,使用 Js 助手删除操作并渲染 ajax

javascript - 如何使用 lodash _isEmpty 检查对象是否为空?

grails - Grails:用户输入了格式化的字符串,但未保留格式

java - Griffon 支持哪些 Java 版本?