Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs4 Combobox with additional options

Tags:

extjs

extjs4

I wish to create a combobox that loads a store, but also want to add a few predefined data on it. Is it possible?

like image 575
jaycode Avatar asked Dec 20 '25 06:12

jaycode


2 Answers

I think this is what you need:

Ext.define('App.widget.MyCombo', {
    extend  : 'Ext.form.field.ComboBox',
    displayField: '...',
    valueField  : '...',
name : '...', alias : 'widget.mycombo', fieldLabel : 'My Custom combo',
initComponent: function() {
    var me = this;

    me.store = Ext.create('Ext.data.Store', {
        model : '...',
        proxy : {
            type : '...',
            reader: '...'
        }
    });

    /*After data is loaded append some predefined records.*/    
    me.store.on('load', function() {
        /*Indicates that data must be appended to already loaded data.*/
        var append = true;

        me.store.loadData([{id : -1, value : 'Default'}, 
                           {id: -2, value: 'Second Default'}], append);
    });

    me.callParent();
}

});

like image 125
Zango Avatar answered Dec 23 '25 08:12

Zango


If your store is a list, then you can simply append your items to the list after it is generated at the index you specify.

You can also get the store from the combobox, and then use add() at the index your specify.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!