jaycode
jaycode

Reputation: 2958

Extjs4 Combobox with additional options

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

Upvotes: 3

Views: 1213

Answers (3)

Zango
Zango

Reputation: 2387

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

});

Upvotes: 5

Reda Bouaichi
Reda Bouaichi

Reputation: 49

As Brian Said, you can "insert" it at the index you specify. When you use "add", it basically appends it to the end of the store. Here is the signature of the insert function:

insert( Number index, Ext.data.Model[] records )

Upvotes: 1

user4903
user4903

Reputation:

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.

Upvotes: 2

Related Questions