View Full Version : How to reinitialize combobox

18 Sep 2012, 8:21 AM
Dear community, help me resolve this trouble

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);
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);

Tim Toady
18 Sep 2012, 10:44 AM
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
Try this:

// 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.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
Dont work if store instance same =(

Tim Toady
19 Sep 2012, 7:37 AM
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
i'm agree the simplest way - recreate combo

19 Sep 2012, 7:59 AM
Немного не так понял. Мне нужно ленивое объявление полей для стора. До того как прийдет ответ от сервера, я не могу написать так: "fields: ['id', 'title'], c.valueField = 'id'".
Если в двух словах, то мне нужен такой комбобокс чтоб мог отображать объекты коллекций с любыми полями, без необходимости менять руками скрипт и без необходимости передавать в скрипт метаинформацию. И в моей задаче если для valueField я могу закрепить одно постоянное поле, то displayField у меня может меняться от запуска к запуску.

19 Sep 2012, 8:07 AM
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.