Reputation: 2958
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
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
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
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