PDA

View Full Version : Do we need the total Records count every time during the pagination process in grid



durgaprasadn
13 Apr 2012, 6:26 AM
My service is responding with the total records and json data for the first time.


{"totalRecords":849,"vanityUrls":[[29851,8,"www.myowncompany.com/content/myowncompany/en_US/
abcdtest","www.myowncompany.com/abcdtest",0,"ABCD Test","ABCD Test",
1333637158483,null,null,"Durga",null,0,"EN_US"],
[29852,8,"www.myowncompany.com/content/myowncompany/en_US/
abcdtest","www.myowncompany.com/abcdtest",0,"ABCD Test","ABCD Test",
1333637158483,null,null,"Durga",null,0,"EN_US"]]}


Subsequent calls, service is returning the data with "totalRecords":null. When "totalRecords" is returned as null, my paging is disturbed with only one page being taken. Is there any alternate way of fixing this problem with out service sending the totalRecords every time. Caching of that initial value in the client side and then use the same value through out the pagination process.


{"totalRecords":null,"vanityUrls":[[29851,8,"www.myowncompany.com/content/myowncompany/en_US/
abcdtest","www.myowncompany.com/abcdtest",0,"ABCD Test","ABCD Test",
1333637158483,null,null,"Durga",null,0,"EN_US"],
[29852,8,"www.myowncompany.com/content/myowncompany/en_US/
abcdtest","www.myowncompany.com/abcdtest",0,"ABCD Test","ABCD Test",
1333637158483,null,null,"Durga",null,0,"EN_US"]]}


My store implementation is as follows and expect the totalRecords count every time during the pagination process.


var store = Ext.create('Ext.data.JsonStore', {
autoDestroy: true,
model: 'VanityUrl',
proxy : new Ext.data.HttpProxy({
method : 'GET',
idIndex: 0,
prettyUrls: false,
params : {
vanityUrl : 'www.myowncompany.com/efghtest',
pageSize : 10
// pageNumber : 1
},
type : 'json',
//url:'http://localhost:4502/apps/vanityUrl/getVanityUrl', // see options parameter for CQ.Ext.Ajax.request

api: {
// all actions except the following will use above url
read : 'http://localhost:4502/apps/myvanity/getVanityUrl/'
//update : 'http://localhost:4502/vanityUrl/saveOrUpdateVanityUrl',
},headers: {
'Accept': 'application/json',
'Content-Type' : 'application/json'
}, reader :{
type: 'json',
root: 'vanityUrls',
totalProperty: 'totalRecords'
},writer: {
type: 'json',
writeAllFields: false,
allowSingle: false,
encode: true,
root: 'row'}


})
});


--Durga

mitchellsimoens
13 Apr 2012, 8:22 AM
Yes, you should always return the total count when using paging. The number of pages is recalculated every time, this is because we don't assume you start at the first page of data.

durgaprasadn
13 Apr 2012, 8:29 AM
Thank you sir for your reply. I made the change in the service to return the totalrecords count every time.