Grails分页:如何使用分页

Grails分页:如何使用分页,grails,datatables,pagination,Grails,Datatables,Pagination,我有一个订单列表(20000条记录),加载速度非常慢, 我正在寻找一种方法,只加载前十个,然后激活分页您提供的信息很少,因此很难说最好的解决方案是什么 我正在寻找一种方法,只加载前十个,然后激活 分页 我不知道你说的“激活分页”是什么意思 假设您使用的是GORM,检索前10条记录的方法可能是这样的 YourDomainClass.list(offset:0, max: 10) 要检索下一个10 YourDomainClass.list(offset: 10, max: 10) 等等 您可以使

我有一个订单列表(20000条记录),加载速度非常慢,
我正在寻找一种方法,只加载前十个,然后激活分页

您提供的信息很少,因此很难说最好的解决方案是什么

我正在寻找一种方法,只加载前十个,然后激活 分页

我不知道你说的“激活分页”是什么意思

假设您使用的是GORM,检索前10条记录的方法可能是这样的

YourDomainClass.list(offset:0, max: 10)
要检索下一个10

YourDomainClass.list(offset: 10, max: 10)
等等

您可以使用类似于
YourDomainClass.count()
的方法找到记录的总数,并使用它反复调用
.list(…)
方法来检索所有记录,每次检索10条

我希望这能有所帮助。

请参考此

域类:

class DataEntry{
    String sendersName
}
class TransactionsController {
    def list() {
        [data: DataEntry.list(params), dataEntryCount: DataEntry.count()]
    }
}
<g:paginate controller="transactions" action="list" total="${dataEntryCount}" />
控制器:

class DataEntry{
    String sendersName
}
class TransactionsController {
    def list() {
        [data: DataEntry.list(params), dataEntryCount: DataEntry.count()]
    }
}
<g:paginate controller="transactions" action="list" total="${dataEntryCount}" />
分页代码:

class DataEntry{
    String sendersName
}
class TransactionsController {
    def list() {
        [data: DataEntry.list(params), dataEntryCount: DataEntry.count()]
    }
}
<g:paginate controller="transactions" action="list" total="${dataEntryCount}" />

<g:paginate next="Forward" prev="Back"
            maxsteps="0" controller="transactions"
            action="list" total="${dataEntryCount}" />


有关更多详细信息,请参阅

您尝试了什么?你尝试的东西有什么不起作用?这个问题太笼统了,不能给出一个很好的答案。我的列表工作很慢,我想让它更快,我现在只需要加载前十个元素,然后我使用分页加载其余元素(对不起,我的英语)Rahul的回答下面描述了如何配置带有分页控件的GSP。你的问题并不表明你正在使用普惠制。他的答案是你想要的吗?@MamoudouNdiaye为什么你更喜欢
Order.createCriteria().list(max:10,offset:0){}
而不是
Order.list(max:10,offset:0)
?对于前者,您分配的是一个
闭包
,该闭包不起任何作用,涉及的框架部分没有任何贡献,但无论如何都在参与。事实上,我只想进行服务器端分页。我尝试了以下方法:def getListOrder(){def employeList=Order.createCriteria().list(最大值:10,偏移量:0){if(params.numero&&!”.equals(params.numero)){ilike(“numero”,“%${params.numero}%”}}def totalRows=employeList.totalCount def collection=employeList.collection{[numero:it.numero]}def result=[total:totalRows,rows:collection]呈现结果为JSON}在Mamoudou在另一个答案上留下的注释中,他们表示没有使用GSP。