Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pagination in Grails

I want to add some pagination stuff to my grails app. I have the list action and in it I did this:

if(!params.max){
params.max = 3
}
    def query = Profile.where {
        userType == "F"
    }
    def freelancers = query.list(sort:"firstName", max:params.max)
    if(freelancers) {
        def freelancersCount = query.count()
        return[freelancer:freelancers, fCount:freelancersCount]
    } else {
        response.sendError(404)
    }

in gsp I wrote this:

<div id="paginate">
    <g:paginate controller="freelancers" action="list" total="${fCount}"/>
</div>

everything is ok, a have a 5 objects in my db and i can see only 3 when open a gsp page in browser, but when I click on the Next to open other 2 object, I see the same 3 ones. what is wrong and what I must to do?

like image 649
Jack Daniel Avatar asked Jul 16 '12 15:07

Jack Daniel


1 Answers

You need to pass the offset into your call to list:

def freelancers = query.list(sort:"firstName", offset:params.offset, 
max:params.max)
like image 132
Nathan Hughes Avatar answered Sep 29 '22 00:09

Nathan Hughes