Take the 2-minute tour ×

I am using ExtJS 3.3.1 with Grails 2.0 to do pagination on screen, but it does not work as I expect. I followed the tip posted here: Grails extJS grid paging
JS page

paramNames: {start:'offset',limit:'max',sort:'sort',dir:'order'},
baseParams: {offset:0,max:10},

The pagingToolbar:

this.gridBBar = new Ext.PagingToolbar({
            pageSize : 10,
            store : this.gridStore,
            displayInfo : true,
            displayMsg  : 'Hiển thị {0} - {1} mục tìm được của {2} kết quả',
            emptyMsg : 'Không tìm thấy dữ liệu',


def result = Floor.createCriteria().list(
render ([count:result.totalCount,data:result] as JSON)

but the paging button (Next) was disabled because the store just contained only 10 item, no more to retrieve.
When I change the offset to 10:

baseParams: {offset:10,max:10},

the pagination is work well, except one strange thing: the grid always display the next 10 results (10th-20th record for 1st click, 20th-30th record for 2nd), not the current first 10 results. I don't know what the correct usage of pagination combined from ExtJs and Grails is. If you have experience in this problem, could you please share me some information?
Thank you so much.

share|improve this question
What does your json look like? You may want to look at this: shitmores.blogspot.com/2007/04/… –  chrislovecnm Mar 6 '12 at 19:31
The returned JSON is {"count":10, "items":[{"id":1, "name" : "AA"}, {"id":2, "name" : "B"}]}. I see that the statement render ([count:result.totalCount,data:result] as JSON) is not correct because the return list does not have the getTotalCount() method or totalCount property –  napoleonit76 Mar 6 '12 at 19:44
add comment

1 Answer

up vote 0 down vote accepted

Oh how lucky I am. I've got it!
Based on these 2 articles:
1. http://grails.1312388.n4.nabble.com/Find-Count-for-pagination-And-Objects-for-Criteria-td1368528.html
2. http://blog.jeffshurts.com/2010/04/grails-pagination-and-criteriabuilder/
I have found the explanation for this. Because the "count" property returned in JSON is got from result.size(), so it always equals to the pageSize of PagingToolbar of the grid's store, so the store will understand that, there is no more any result to retrieve and it will disable the navigation buttons.
The key here is returning the real total result of the query (without attaching pagination constraints). As normal, the createCriteria().list {} will return an ArraysList. But by passing paging params to list as below: (refer to link 1)

DomainClass.createCriteria().list(max : x, offset : y) { 
// not pass max : x, offset : y to here, inside the body

Grails will return the result as a PagedResultList implicitly (refer to link 2), and it provide us the getTotalCount(). There's no any official documentation of Grails mention this magical issue. And my problem was solved.

share|improve this answer
add comment

Your Answer


