2013-07-13 43 views
0

我尝试从我的控制器中显示一个自定义列表,但是当我想使用分页时, 不起作用:例如,如果我想显示10个条目(params。 max = Math.min(max?:10,100)),在我的gsp列表视图中,所有条目都显示在同一页面中。我也注意到我有分页,但是当我使用它时,我仍然显示了所有条目。 我的代码带参数的Grails findByAll不起作用

def user = User.findByLogin("John") 
List MyList 

switch (userView){ 

case "mylist": 

    params.sort="date" 
    params.order="desc" 
    params.max = Math.min(max ?: 10, 100) 

    MyList = DS.findAllByCpCreator(user,[params:params]) 

case ... 

... 

def DSList = MyList      
def DSCount = MyList.size() 
[DSInstanceList: DSList, DSInstanceTotal: DSCount,userView:userView] 

在GSP的看法,我修改这样的分页:

<div class="pagination"> 
    <g:if test="${userView!=null}"> 
     <g:paginate total="${DSInstanceTotal}" params="${[q:userView]}" /> 
    </g:if> 
    <g:else> 
     <g:paginate total="${DSInstanceTotal}" /> 
    </g:else> 
</div> 

回答

0

在你的行动,你逝去的findAll *地图的地图,它应该是:

MyList = DS.findAllByCpCreator(user, params) 

编辑:实际上你的看法标签是确定

对于计数,你应该使用:http://grails.org/doc/2.2.x/ref/Domain%20Classes/countBy.html

DSCount = DS.countByCpCreator(user) 
+0

我注意到“DSCount = MyList.size()”不正确,因为我需要获取有关用户名的所有条目。 因此,我还需要添加:“DSCount = DS.findAllByCpCreator(user) – Jils

+0

对于count,您应该使用DS.countByCpCreator(用户)。http://grails.org/doc/2.2.x/ref/Domain %20Classes/countBy.html – ikumen