質問

I try to display a custom list from my controller, but when I want to use the pagination, it doesn't work: for example if I want to diplay 10 entries (params.max = Math.min(max ?: 10, 100)), in my gsp list view all entries are displayed in the same page. I also noticed that I have pagination but I when I use it, I still have all entries displayed. My code

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]

In gsp view, I modified the pagination like this:

<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>
役に立ちましたか?

解決

In your action, you are passing findAll* a map of maps, it should be:

MyList = DS.findAllByCpCreator(user, params)

EDIT: actually your view tag is ok

For count, you should use: http://grails.org/doc/2.2.x/ref/Domain%20Classes/countBy.html

DSCount = DS.countByCpCreator(user)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top