If you need combos accessing large tables the remote store and using combo to search these tables is best solution. If the combo's mode is 'remote', it loads it's store on trigger click. Suggested procedure:
Have server generate this code in header before instantiation of combo(s):
YourScope.static.yourData = [ [1, 'item1'] ,[2, 'item2'] ];
var yourData = [ [1, 'item1'] ,[2, 'item2'] ];
var combo = new Ext.form.ComboBox({ store: new Ext.data.SimpleStore({ id:0 ,fields: [ 'myId', //numeric value is the key 'myText' //the text value is the value ] ,data:YourScope.static.yourData }) ,valueField:'myId' ,displayField:'myText' ,mode:'local' // rest of config });
var combo = new Ext.form.ComboBox({ ... mode: 'remote', ... listeners: { beforequery: function(qe){ delete qe.combo.lastQuery; } } });
Configure the select event:
var cb = new Ext.form.ComboBox({ // all of your config options listeners:{ scope: yourScope, 'select': yourFunction } });
Alternatively, you can assign events after the object is created:
var cb = new Ext.form.ComboBox(yourOptions); cb.on('select', yourFunction, yourScope);
var modelRecord = new Ext.data.Record.create([{name: 'model'}]); var brandJReader = new Ext.data.JsonReader({ totalProperty: 'brandCount', root: 'brandData', id: 'brand'}, [{name: 'brand'}]); var modelJReader = new Ext.data.JsonReader({ totalProperty: 'modelCount', root: 'modelData', id: 'model'}, [{name: 'model'}]); var brandStore = new Ext.data.Store({ proxy: new Ext.data.HttpProxy( {url: 'some_url1', method: 'GET'} ), reader: brandJReader, autoLoad: true }); var modelStore = new Ext.data.Store({ {url: 'some_url2', method: 'GET'} ), reader: modelJReader }); var formPanel = new Ext.FormPanel({ title:'Choose car...', frame: true, width: 750, labelWidth: 175, style:'margin:5px 5px', bodyStyle:'padding:10px', defaults: {xtype:'combo'}, items:[ new Ext.form.ComboBox ({ fieldLabel:'Select Brand', displayField:'brand', valueField:'brand', id: 'brands', store: brandStore, triggerAction:'all', mode:'local', listeners:{select:{fn:function(combo, value) { var modelCmp = Ext.getCmp('models'); modelCmp.setValue(''); modelCmp.setDisabled(false); modelCmp.store.reload({ params: { brand: combo.getValue() } }); }}} }), new Ext.form.ComboBox ({ fieldLabel:'Select Model', displayField:'model', valueField:'model', id:'models', disabled: true, store: modelStore, triggerAction:'all', mode:'local', autoHeight: true }) ], buttons: [ { text: 'Get Car' } ] }); var centerSide = new Ext.TabPanel({ region:'center', split:true, height: 600, deferredRender:false, activeTab:0, margins:'0 0 0 5', items:[{ contentEl:'carTab', title: 'Cars', autoScroll:true, items: [formPanel] },{ contentEl:'mcTab', title: 'Motorcycles', autoScroll:true }] });
var store = new Ext.data.JsonStore({ url: 'myurl', reader: new Ext.data.JsonReader( { root: 'data' }, //fields: [ {name:'id'}, { name:'title', convert: function(v){ //manipulate v here console.log('Converting the title, where v = ',v); return unescape(v); } } ] ) }); store.on('load', function(s, r) { Ext.each(r, function(rec) { rec.data.title = unescape(rec.data.title); }); }); var combo = new Ext.form.ComboBox({ id: 'combo1', applyTo: 'mycombo', store: store, valueField:'id', displayField: 'title', hideTrigger:false, triggerAction: 'all' });
ComboBox has a change or select event that you want to subcribe to.
listeners:{ change:function(combo, ewVal, oldVal) { // do something } }to the config of your ComboBox.
Ext.override(Ext.form.ComboBox, { setValue : function(v){ //begin patch // Store not loaded yet? Set value when it *is* loaded. // Defer the setValue call until after the next load. if (this.store.getCount() == 0) { this.store.on('load', this.setValue.createDelegate(this, [v]), null, {single: true}); return; } //end patch var text = v; if(this.valueField){ var r = this.findRecord(this.valueField, v); if(r){ text = r.data[this.displayField]; }else if(this.valueNotFoundText !== undefined){ text = this.valueNotFoundText; } } this.lastSelectionText = text; if(this.hiddenField){ this.hiddenField.value = v; } Ext.form.ComboBox.superclass.setValue.call(this, text); this.value = v; } });