PDA

View Full Version : How to make store pageSize work with store.loadData for grid.Panels



ci11111
27 Mar 2012, 2:30 AM
I have a Store with pageWidth: 6
a gridPanel, using this store, but when loading data, through grid.getStore().loadData(myarray);
I have more than 6 lines, all showing in page 1/1

additionally, trying to refresh the grid form the bbar, will cause a TypeError: Cannot read property 'length' of undefined

exactly like is I do grid.getStore().load(), probably normal since I didn't use any proxy, I'm just loading the store manually on demand.

Or do I have to use a store proxy reader, to query directly the store? but why it's not working in the first case

sskow200
27 Mar 2012, 4:42 AM
Your data needs to be in the form of :



{
message: 'Success',
data: [
{'Field1: 'Value1'},
{'Field2:' Value'1}
],
total: 107 <-- this is configured in the totalProperty of the stores reader
}



Without the total records property in the results, the paging cannot perform the calculations necessary and hense uses the number of records in the store.

ci11111
27 Mar 2012, 5:15 AM
I have changed


resultList.getStore().loadData(j);

in


var total = j.length;
resultList.getStore().load({message: 'Success', data: j, total: total});

and have directly TypeError: Cannot read property 'length' of undefined

sskow200
27 Mar 2012, 6:26 AM
Well, that's because your var j is undefined and has not length. Which is not indication of whether your method is working or not because you don't have any data. Also, you cannot do:




resultList.getStore().load({message: 'Success', data: j, total: total})


Calling it this way implies remote data in which you cannot feed the data directly. You may be looking at trying to do soemthing like this...




resultList.getStore().loadData({message: 'Success', data: j, total: total});


Although, I am not quite sure why you're paging at all if you have all the data already client side. Seems like remote paging is what you would want anyway.

ci11111
27 Mar 2012, 6:57 AM
j is a valid json, it's length (it's an array) is valid also

right, if I do this, my list will be empty

I need to have a store that will applyData, using the data attribute from the json


var store = Ext.create('Ext.data.Store', { fields: ['publisherID', 'publisherName','city', 'text'],
sorters: ['publisherName'],
groupField: 'city',
pageSize: 6
});

how would I do that please?

sskow200
28 Mar 2012, 1:05 PM
Have you configured your reader to use the 'data' property?




var store = Ext.create('Ext.data.Store', {
fields: ['publisherID', 'publisherName', 'city', 'text'],
sorters: ['publisherName'],
groupField: 'city',
pageSize: 6,
proxy: {
type: 'ajax',
reader: {
type: 'json',
root: 'data' <------
}
}
});