限制 Grails 分页问题中的行数

Limiting the number of rows in Grails Pagination Issue

嗨,

如上图所示,我的行和分页没有按预期正常工作。它不是每页显示 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 控制器如下所示。

底部选项无:

<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>

远程分页脚本:

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

在协议导航器中:

        <g:applyLayout name="bottomOptionsnone">

DailyJobActivity 控制器

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.. 但如上所示,此页面中的行数更多。

有人可以帮忙吗?提前致谢。

来自Documentation

maxsteps (optional) - The number of steps displayed for pagination (defaults to 10). Used ONLY if params.maxsteps is empty

注意 maxStep 用于确定 分页链接的数量 而不是 items/records 的数量。

为此你必须max,再次从文档

max (optional) - The number of records to display per page (defaults to 10). Used ONLY if params.max is empty

关于 max 的重要一点是如果存在 params.max 那么 g:paginate 将忽略此属性。 g:paginate 放置一些属性,例如 max 用于 每页中的记录数 offset 用于 记录的起始索引 [=35] =] 等 params。您必须在查询数据时使用它们。例如你的控制器代码可以是 li following

    def show(){
    System.out.println "=== Activity ===";
    def data = []
    def job = Dailyjob.get(params.id as Long);

    //preparing max and offset from params
    Integer max = params.max ? params.int("max") : 10
    Integer offset = params.offset ? params.int("offset") : 0

    data = Dailyjobactivity.where { 
        daily_job == job  
    }.list([sort:'activity_datetime', order:'desc', max: max, offset: offset])

    System.out.println "=== Data ==="+data;
    render(view:view_name+'/jobactivity',model:[data:data,instanceTotal:data.size()])
}