PDA

View Full Version : Update grid if totalProperty = 0



catnipper
23 Feb 2010, 3:34 AM
I discovered my grid does not update if reloading the store returns an empty result:

I am using a HTTPProxy with a JsonReader. After I added a bbar including a combobox with predefined values applying a server side filter (paging grid), I discovered the grid will not get updated if the JSON returned is '{"results":0}'.

Playing a little bit with the code, I tried to capture the event with a store listener "load". This seems not to work as the store will never get loaded if the 'totalProperty' is '0'.

Any other ideas/best practice how a grid can be updated (cleared) or an event can be handled if no records have been found?



// create the Data Store
products = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({
url: '/functions/getProducts.php',
method: 'GET'
}),
remoteSort: true,
baseParams:{mode:'JSON',id:id,searchQuery:'2'},

// the return will be JSON, so lets set up a reader
reader: new Ext.data.JsonReader({
root: 'rows',
totalProperty: 'results',

// the fields config option will internally create an Ext.data.Record
// constructor that provides mapping for reading the record data objects

fields: [
'id',
'Products'
]
}),
listeners: {
load: function(licenses){
if(products.baseParams.searchAlert=='1')
alert(products.getTotalCount() + " Products loaded...");
}
}
});
products.load({params:{start:0, limit:10, mode:'JSON',id:id}});


[...]


// paging bar on the bottom
bbar: new Ext.PagingToolbar({
pageSize: 10,
store: products,
displayInfo: true,
displayMsg: 'Display Products {0} - {1} of {2}',
emptyMsg: "No Products to display",
items: [{
xtype : 'combo',
name : 'searchParams',
fieldLabel : 'Default search queries',
valueField : 'searchId',
mode : 'local',
triggerAction: 'all',
editable : false,
store : new Ext.data.SimpleStore({
fields : ['searchId', 'textSearch'],
data : [['1','Filter1'],['2','Filter2']]
}),
displayField :'textSearch',
width : 150,
allowBlank : true,
listeners: {
render: function(combo){
combo.setValue('2');
return true;
},
select: function(combo){
products.setBaseParam('searchQuery',combo.getValue());
products.setBaseParam('searchAlert','2');
products.load({params:{start:0, limit:10}});
}
}
}]
})

Animal
23 Feb 2010, 3:49 AM
It still needs "rows: []"

It will still evaluate that.

The count is the TOTAL size of the dataset.

catnipper
1 Mar 2010, 1:39 AM
Thank's Animal,
this did the job!