1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    4
    Vote Rating
    0
    lool is on a distinguished road

      0  

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

  2. #2
    Sencha User Tim Toady's Avatar
    Join Date
    Feb 2010
    Location
    Pennsylvania
    Posts
    544
    Answers
    61
    Vote Rating
    96
    Tim Toady is a glorious beacon of light Tim Toady is a glorious beacon of light Tim Toady is a glorious beacon of light Tim Toady is a glorious beacon of light Tim Toady is a glorious beacon of light

      0  

    Default


    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.

  3. #3
    Sencha User
    Join Date
    May 2011
    Location
    Ukraine, Rivne
    Posts
    250
    Answers
    44
    Vote Rating
    42
    redraid has a spectacular aura about redraid has a spectacular aura about redraid has a spectacular aura about

      0  

    Default


    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 Ext.create('Ext.form.ComboBox', {
        
    fieldLabel'Choose State',
        
    storestates,
        
    queryMode'local',
        
    displayField'name',
        
    valueField'abbr',
        
    renderToExt.getBody()
    });
    Ext.create('Ext.button.Button', {
        
    text'test',
        
    renderToExt.getBody(),
        
    handler: function () {
            
    c.reset();
            
    c.displayField 'title';
            
    c.valueField 'id';
            
    c.picker.destroy(); // Destroy old picker
            
    c.createPicker(); // Recreate picker
            
    c.bindStore(states2true); // Bind new store
        
    }
    }); 

  4. #4
    Sencha User
    Join Date
    May 2011
    Location
    Ukraine, Rivne
    Posts
    250
    Answers
    44
    Vote Rating
    42
    redraid has a spectacular aura about redraid has a spectacular aura about redraid has a spectacular aura about

      0  

    Default


    Dont work if store instance same =(
    Last edited by redraid; 19 Sep 2012 at 7:32 AM. Reason: fix

  5. #5
    Sencha User Tim Toady's Avatar
    Join Date
    Feb 2010
    Location
    Pennsylvania
    Posts
    544
    Answers
    61
    Vote Rating
    96
    Tim Toady is a glorious beacon of light Tim Toady is a glorious beacon of light Tim Toady is a glorious beacon of light Tim Toady is a glorious beacon of light Tim Toady is a glorious beacon of light

      0  

    Default


    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.

  6. #6
    Sencha User
    Join Date
    May 2011
    Location
    Ukraine, Rivne
    Posts
    250
    Answers
    44
    Vote Rating
    42
    redraid has a spectacular aura about redraid has a spectacular aura about redraid has a spectacular aura about

      0  

    Default


    i'm agree the simplest way - recreate combo

  7. #7
    Sencha User
    Join Date
    Jul 2012
    Posts
    4
    Vote Rating
    0
    lool is on a distinguished road

      0  

    Default


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

  8. #8
    Sencha User
    Join Date
    Jul 2012
    Posts
    4
    Vote Rating
    0
    lool is on a distinguished road

      0  

    Default


    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.

Thread Participants: 2

Tags for this Thread