限制Grails分页问题

时间:2015-09-18 05:54:20

标签: grails pagination gorm grails-2.0 grails-controller

Data Activity monitor

您好,

如上图所示,我有行和分页无法按预期正常工作。它不是每页显示10条记录(查看下面的分页代码),而是显示同一页面中的所有记录,并在所有页面中显示相同的记录。

这是代码:

<!doctype html>
<g:applyLayout name="protocolNavigator">
<meta name="layout" content="page" />
    <head>
        <script type="text/javascript" src="<g:resource dir="BI/d3" file="d3.v2.js"/>"></script>
    </head>
    <content tag="listTitle">
        <label>Data Activity</label>
    </content>
    <content tag="list">    
    <div id="div_print">
            <table border="0" cellpadding="0" cellspacing="0" class="tablesorter">
                <thead>
                    <tr>
                        <th>Study Id</th>
                        <th>Date</th>
                        <th>Start Time</th>
                        <th>Scheduler Name</th>
                        <th>Activity Description</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    <g:each in="${data}">
                        <tr>
                            <td><g:remoteLink action="show" controller="DailyJobActivity" params='[id:"${it?.id}", name:""]' update="[success:'dataBox',failure:'error']" onSuccess="showDataBox()">${it?.study?.name}</g:remoteLink></td>
                            <!-- <td>${it?.provider}</td> -->
                            <td><g:remoteLink action="show" controller="DailyJobActivity" params='[id:"${it?.id}", name:""]' update="[success:'dataBox',failure:'error']" onSuccess="showDataBox()"><g:formatDate format="MMM dd, yyyy HH:mm" date="${it?.last_activity_datetime}"/></g:remoteLink></td>
                            <td><g:remoteLink action="show" controller="DailyJobActivity" params='[id:"${it?.id}", name:""]' update="[success:'dataBox',failure:'error']" onSuccess="showDataBox()"><g:formatDate format="MMM dd, yyyy HH:mm" date="${it?.started_datetime}"/></g:remoteLink></td>
                            <td></td>
                            <td><g:remoteLink action="show" controller="DailyJobActivity" params='[id:"${it?.id}", name:""]' update="[success:'dataBox',failure:'error']" onSuccess="showDataBox()">${it?.job}</g:remoteLink></td>
                            <td><g:remoteLink action="show" controller="DailyJobActivity" params='[id:"${it?.id}", name:""]' update="[success:'dataBox',failure:'error']" onSuccess="showDataBox()">${it?.current_status}</g:remoteLink></td>
                        </tr>
                    </g:each>
                </tbody>
            </table>
             </div>
        </content>
</g:applyLayout>

DailyJobActivity Controller如下所示。

BottomOptionsNone:

<div class="bottoMenu">
    <div class="pg">    
        <g:if test="${instanceTotal != null}">
            <g:if test="${remotePagination == true}">
                <util:remotePaginate action="${params.action}" params="${params}" total="${instanceTotal}" maxsteps="10" onSuccess="showDataBox()" update="[success:'dataBox',failure:'error']" /> 
            </g:if>
            <g:else>
                <g:paginate maxsteps="10" action="${params.action}" total="${instanceTotal}" params="${params}"/>
            </g:else>
        </g:if>
    </div>
</div>

RemotePagination脚本:

<script>remotePagination
                if (typeof (hideMsg) != "undefined")
                    hideMsg()
            </script>

在protocolnavigator中:

        <g:applyLayout name="bottomOptionsnone">

DailyJobActivity Controller

package com.datumrite.sdtm
import java.text.SimpleDateFormat;
import com.datumrite.master.*;
import com.datumrite.BaseController
import com.datumrite.sdtm.Dailyjob


@Mixin(BaseController)
class DailyJobActivityController {
    def commonService;
    def view_name='/dataManagement/DailyJob'
    def protoId 
    def providerId
    def index() { }

    def show(){
        System.out.println "=== Activity ===";
        def data = []
        def job = Dailyjob.get(params.id as Long);
        data = Dailyjobactivity.where { 
        daily_job == job  
        }.list([sort:'activity_datetime',order:'desc'])
        System.out.println "=== Data ==="+data;
        render(view:view_name+'/jobactivity',model:[data:data,instanceTotal:data.size()])
    } 
}

我已经将最大步数设为10 ..然后相应调用..但它没有被反映出来。

我想要不。行数为10 ..但如上所示,它在此页面中更多。

任何人都可以帮忙吗?提前致谢。

1 个答案:

答案 0 :(得分:1)

来自Documentation

  

maxsteps(可选) - 分页显示的步数(默认为10)。仅在params.maxsteps为空时使用

注意maxStep用于确定分页链接的数量而非项目/记录的数量

为此,您必须再次从文档

max
  

max(可选) - 每页显示的记录数(默认为10)。仅在params.max为空时使用

关于max的重要事项是,如果存在params.max,则g:paginate将忽略此属性。 g:paginate为{em>每页记录创建了一些属性,max,{{1>}为{em>记录的开头索引等offset 1}}。您必须在查询数据时使用它们。例如,你的控制器代码可以跟随

params