PDA

View Full Version : Replace store in grid



Radius-Service
11 Nov 2011, 2:17 AM
Ext.create('Ext.data.Store', {
storeId : 'vProductsParam.ds',
model : 'mdl_cassemblyparameter'
});

Ext.create('Ext.data.Store', {
storeId : 'vProductsParam.ds_2',
model : 'mdl_cdisassemblyparameter'
});

Ext.create('Ext.grid.Panel', {
id : 'vProductsParam.grid',
store : 'vProductsParam.ds',
viewConfig: {
allowDeselect: true,
stripeRows: true
},
flex: 1,
columns: [
{text: '?', dataIndex: 'ID', width: 35, renderer: addTooltip}
]
});

loadData = function(){
Ext.getCmp('vProductsParam.grid').store = Ext.StoreMgr.lookup('vProductsParam.ds_2');
Ext.getCmp('vProductsParam.grid').getStore().load();
}

After executing the functions "loadData()", load the correct data, but for display come from the old.

How to update the grid?

tvanzoelen
11 Nov 2011, 2:52 AM
I allways clear the store in Extjs4 before reloading a grid



clearStore: function(grid) {

if (grid.store.getCount() > 0) {
grid.store.removeAll();
grid.view.refresh();
}
}

tvanzoelen
11 Nov 2011, 2:56 AM
setting an other store on the grid must be done with reconfigure. You can not do


grid.store = newstore

but do


grid.reconfigure(newstore);

so reconfigure first and to be sure clear the data from the store before doing a reload.

Radius-Service
13 Nov 2011, 9:28 PM
if (Ext.getCmp('grid').store.getCount() > 0) {
Ext.getCmp('grid').store.removeAll();
Ext.getCmp('grid').view.refresh();
}

Ext.getCmp('grid').reconfigure(Ext.StoreMgr.lookup('ds_2'));
Ext.getCmp('grid').getStore().proxy.extraParams.prt = Ext.getCmp('combo_producttype').getValue();
Ext.getCmp('grid').getStore().load();


Result:
29263

New data load - correct.
Fields in the new and the old store are the same (but different names of models.).

What am I doing wrong?

skirtle
14 Nov 2011, 1:36 AM
ExtJS version? In 4.0.2 there was a bug such that you had to pass in the columns as part of reconfigure even if they hadn't changed. This works fine in 4.0.7.

It shouldn't be necessary to clear out the old store first unless it's a bug workaround. Once you've got everything else working, try removing that code. It might not be needed in whatever version you're using.

Radius-Service
14 Nov 2011, 2:51 AM
ExtJS version?
Thank you. And indeed, it works.
But let's wait for the next release, I can not use 4.0.7 because of another unsolved problem: http://www.sencha.com/forum/showthread.php?151943-Fields-with-trigger.-Width.