How to change Ext js store data dynamically
Asked Answered
M

3

6

I have a combobox which looks like below

{
  xtype:'combo',
  fieldLabel:'Test',
  store:['a','b']
}

Without creating Ext store object I am assigning the array to store and it is displaying the values fine.

At some action i want to update the store with ['d','e']

I have tried by assigning the new values to store like below

comboObje.store=['d','e'];

but it is not updating the values.

how to replace the orginal values with new values in the store.

Mckenney answered 3/9, 2015 at 16:49 Comment(0)
N
9

You can create a new store using bindStore or just load new data to the existing store using loadData:

combo.store.loadData(['d', 'e'].map(function(item){ return [item]; }));

Working example: https://fiddle.sencha.com/#fiddle/tb1

Negro answered 3/9, 2015 at 18:42 Comment(0)
E
3

In version 5.* and higher you can use:

comboObje.setStore(['d','e']);

This doesn't work in previous versions.

Paste the following code into a Sencha Fiddle as a 'proof-of-concept':

Ext.application({
    name : 'Fiddle',

    launch : function() {
        var panel = Ext.create('Ext.form.Panel', {
            title: 'test',
            items: [{
                xtype:'combo',
                fieldLabel:'Test',
                store:['a','b']
            }],
            renderTo: Ext.getBody()
        });

        panel.down('combo').setStore(['d','e']);
    }
});
Exsect answered 3/9, 2015 at 18:7 Comment(5)
It is absolutely working. No doubt. I will edit my answer.Exsect
Ok let me make a fiddleMckenney
Nope your example is not working in jsfiddle.net/tsuryap/6zfcbnzz/11 .. I am using Ext js 4.2 I was lol when i executed your example in in fiddleMckenney
Your proof of concept is failed in ext js 4.2Mckenney
Yes, I saw that. Didn't realize that setStore doesn't exist in 4.2.*. In 5.* and higher it works perfectly though. Sorry to point you in the wrong direction.Exsect
R
2

Try this:

comboObje.getStore().loadData([{'field1': 'd'}, {'field1': 'e'}]);

When you assign an array to 'store' config, ExtJS automatically generates field names.

Rheingold answered 3/9, 2015 at 19:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.