-
18 Sep 2012 8:21 AM #1
Unanswered: How to reinitialize combobox
Unanswered: How to reinitialize combobox
Dear community, help me resolve this trouble
Code:#combobox constructor: function (config){ config.store = Ext.create('Ext.data.Store', { fields: [], proxy: {...} }); config.store.on('load', function(store, records, status){ fields = Ext.Object.getKeys(store.first().raw); store.model.setFields(fields); var displayField = 'any property name from fields array'; this.displayField = displayField; //do not help this.getPicker().displayField = displayField; //do not help //what i need to here to reinitialize combobox //and that new displayField using }, this); this.callParent(arguments); }
-
18 Sep 2012 10:44 AM #2
AFAIK, there is no way to reconfigure it out of the box. You are better off removing the existing combo and replacing it with a new one than trying to hack it to work.
-
19 Sep 2012 7:17 AM #3
Try this:
PHP Code:// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
//...
]
});
var states2 = Ext.create('Ext.data.Store', {
fields: ['id', 'title'],
data : [
{"id":"1", "title":"11111"},
{"id":"2", "title":"22222"},
{"id":"3", "title":"33333"}
//...
]
});
// Create the combo box, attached to the states data store
var c = Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody()
});
Ext.create('Ext.button.Button', {
text: 'test',
renderTo: Ext.getBody(),
handler: function () {
c.reset();
c.displayField = 'title';
c.valueField = 'id';
c.picker.destroy(); // Destroy old picker
c.createPicker(); // Recreate picker
c.bindStore(states2, true); // Bind new store
}
});
-
19 Sep 2012 7:24 AM #4
Dont work if store instance same =(
Last edited by redraid; 19 Sep 2012 at 7:32 AM. Reason: fix
-
19 Sep 2012 7:37 AM #5
You would also need to replace the displayTpl if you are going that route otherwise when you select it you wont see anything. I still think it is cleaner to simply create a new combo and destroy the old one. Trying to change it requires hackery which is more susceptible to upgrade issues.
-
19 Sep 2012 7:42 AM #6
i'm agree the simplest way - recreate combo
-
19 Sep 2012 7:59 AM #7
Немного не так понял. Мне нужно ленивое объявление полей для стора. До того как прийдет ответ от сервера, я не могу написать так: "fields: ['id', 'title'], c.valueField = 'id'".
Если в двух словах, то мне нужен такой комбобокс чтоб мог отображать объекты коллекций с любыми полями, без необходимости менять руками скрипт и без необходимости передавать в скрипт метаинформацию. И в моей задаче если для valueField я могу закрепить одно постоянное поле, то displayField у меня может меняться от запуска к запуску.
-
19 Sep 2012 8:07 AM #8
Yes i see what displayTpl is compiling at initializing time. I just thought maybe there is an event which force reinitialize component, maybe private method or etc. Or someone know ux combobox with similar effects.


Reply With Quote