daspunkt
18 Dec 2007, 3:23 AM
This is a combobox that upon rendering autoloads and displays the first entry from its store.
Ext.namespace('Ext.ux');
/**
* @class Ext.ux.ComboBoxAutoLoad
* @extends Ext.form.ComboBox
* A ComboBox that automatically loads the store and displays its first entry.
*/
Ext.ux.ComboBoxAutoLoad = function(config){
Ext.ux.ComboBoxAutoLoad.superclass.constructor.call(this, config);
this.addListener({
'render': function(combo){
if (this.store !== null) {
this.store.load({
callback: function(records, options, success){
if (records.length > 0 && success) {
this.setValue(records[0].data[this.displayField]);
}
},
scope: this
});
}
}
});
};
Ext.extend(Ext.ux.ComboBoxAutoLoad, Ext.form.ComboBox, {});
Usage example:
new Ext.ux.ComboBoxAutoLoad ({
fieldLabel: 'Hostname',
displayField: 'name',
forceSelection: true,
selectOnFocus: true,
lazyInit: false,
mode: 'local',
triggerAction: 'all',
minChars: 0,
store: new Ext.data.Store({
reader: new Ext.data.XmlReader(
{record: "host", success: '@success'},
['name']),
proxy: new Ext.data.HttpProxy({
url: 'rpc.jsp',
method: 'POST'
}),
baseParams: {func: 'getHostNames'}
})
})
Ext.namespace('Ext.ux');
/**
* @class Ext.ux.ComboBoxAutoLoad
* @extends Ext.form.ComboBox
* A ComboBox that automatically loads the store and displays its first entry.
*/
Ext.ux.ComboBoxAutoLoad = function(config){
Ext.ux.ComboBoxAutoLoad.superclass.constructor.call(this, config);
this.addListener({
'render': function(combo){
if (this.store !== null) {
this.store.load({
callback: function(records, options, success){
if (records.length > 0 && success) {
this.setValue(records[0].data[this.displayField]);
}
},
scope: this
});
}
}
});
};
Ext.extend(Ext.ux.ComboBoxAutoLoad, Ext.form.ComboBox, {});
Usage example:
new Ext.ux.ComboBoxAutoLoad ({
fieldLabel: 'Hostname',
displayField: 'name',
forceSelection: true,
selectOnFocus: true,
lazyInit: false,
mode: 'local',
triggerAction: 'all',
minChars: 0,
store: new Ext.data.Store({
reader: new Ext.data.XmlReader(
{record: "host", success: '@success'},
['name']),
proxy: new Ext.data.HttpProxy({
url: 'rpc.jsp',
method: 'POST'
}),
baseParams: {func: 'getHostNames'}
})
})