你好
如上图所示,我有行并且分页无法按预期正常工作。而不是每页显示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">
DailyJob Activity 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()])
}
}
我已经将maxsteps设置为10 ..并进行了相应的调用。.但是没有得到体现。
我要不要的行数为10。.但如上所述,此页中的内容更多。
有人可以帮忙吗?提前致谢。
最佳答案
maxsteps (optional) - The number of steps displayed for pagination (defaults to 10). Used ONLY if params.maxsteps is empty
注意
maxStep
用于确定分页链接的数量而不是项目/记录的数量。为此,您必须再次从文档
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
表示每页中的记录数,params
表示记录的开始索引等。您必须在查询数据时使用它们。例如,您的 Controller 代码可以是li 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()])
}
关于grails - 在Grails分页问题中限制行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32644763/