2013-07-13 36 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