PDA

View Full Version : ComboBox does not reflect updated store



demonraiser
23 Apr 2012, 2:34 AM
I need to dynamically update data in a ComboBox from another store.

var comboStore = myCombo.store;
// replacing the curent store data with that of the other store
comboStore.loadData(otherstore.getRange(), false);
// hopefully my ComboBox will refresh
comboStore.load();
I can see that the store has updated with the new data. But on expanding the combo-box, it still shows the old values.

How do I reflect the updated store data in the ComboBox view?

scottmartin
23 Apr 2012, 8:47 AM
Please see the following:



xtype: 'combo',
listeners: {
beforequery: function(qe){
delete qe.combo.lastQuery;
}
}


Regards,
Scott.

demonraiser
24 Apr 2012, 12:51 AM
I added the listener to my combo, and it was getting called every time I expand the combo. BUT on debugging, I observe that the lastQuery property is never there to delete. The ComboBox still shows old data.

I am using a ArrayStore inside the combo, all my changes are local.
Is
comboStore.loadData(otherstore.getRange(), false); the correct way to copy the content of one ArrayStore into another?

I have noticed another strange thing while debugging:
comboStore.data.items reflect the update data records, but comboStore.totalCount property still shows the previous number of records.

vietits
24 Apr 2012, 1:23 AM
var comboStore = myCombo.store;
// replacing the curent store data with that of the other store
comboStore.loadData(otherstore.getRange(), false);
// hopefully my ComboBox will refresh
comboStore.load();

Why do you call comboStore.load() after calling comboStore.loadData()? This will override what you will do with previous comboStore.loadData().

Let have a try by commenting out comboStore.load().


var comboStore = myCombo.store;
// replacing the curent store data with that of the other store
comboStore.loadData(otherstore.getRange(), false);
// hopefully my ComboBox will refresh
//comboStore.load();

demonraiser
24 Apr 2012, 8:14 AM
Ok, removed that line. Just using


var comboStore = myCombo.store;
comboStore.loadData(otherstore.getRange(), false);

No changes. The ComboBox still shows old data on expanding.

When I debug into the coe and break right after loadData(), I see the comboStore.data is updated, BUT data in comboStore.proxy.data shows old data. How do I update the proxy data (or better, disable the damn proxy)?

Thanks for the responses btw.

vietits
24 Apr 2012, 4:41 PM
FYI: I tried to simulate your case with the following example to switch combo's store between two stores and everything works well.


Ext.onReady(function(){
var current = 0;
var store = [];
store[0] = Ext.create('Ext.data.Store', {
fields: ['f1', 'f2'],
data : [
{f1: 1, f2: 1},
{f1: 2, f2: 2}
]
});
store[1] = Ext.create('Ext.data.Store', {
fields: ['f1', 'f2'],
data : [
{f1: 'a', f2: 'a'},
{f1: 'b', f2: 'b'},
{f1: 'c', f2: 'c'},
{f1: 'd', f2: 'd'}
]
});
var combo = Ext.create('widget.combobox', {
renderTo: Ext.getBody(),
store : {
fields: ['f1', 'f2'],
data : []
},
displayField: 'f2',
valueField: 'f1',
queryMode: 'local'
});
Ext.create('widget.button', {
renderTo: Ext.getBody(),
text: 'Switch store',
handler: function(){
combo.store.loadData(store[current++ % 2].getRange(), false);
}
});
});

demonraiser
25 Apr 2012, 12:49 AM
Thanks vietits, on looking at your code, I realized that I had set mode instead of queryMode to local.

Once I fixed that, it all worked fine. I shall read the documentation more carefully next time.