-
18 Dec 2007 10:57 PM #1
How to get DataView of a comboBox to make a default selection
How to get DataView of a comboBox to make a default selection
Hi,
Im creating a comboBox for which i want to set the First Element in the View as the Default selection.. I tried combo.select(0), but i get an error that reads "this.view has no properties"..
I tried creating a dataView, associating with the store im using and assigned it to the comboBox im using, combo.view(myDataView), but din work, as the dataView is not rendered..
How to go abt this..Plz help..
<code>
//Store
var store = new Ext.data.SimpleStore({
fields: ['item', 'action'],
data : CItems
});
//combo
var combo = new Ext.form.ComboBox({
store: store,
displayField:'item',
applyTo: 'combo-action',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select an action...',
selectOnFocus:true,
resizable:true,
listeners:{
select:{
fn:function(combo, record, index) {
var qq= record.get('action').valueOf();
eval(qq+'('+')');
}}
}
});
//This doesnt work. says "this.view has no properties"
combo.select(0, true);
</code>
Cheers,
Vishnupriya
-
18 Dec 2007 11:25 PM #2
Set the value of your combobox to your default selection. Or have i not understood your question?
Make everything as simple as possible, but not simpler.
- Albert Einstein
-
19 Dec 2007 12:02 AM #3
Thanks Santhosh.. It Worked.. This is how i got it done.. Pls let me know if any other efficient way is available..
var combo = new Ext.form.ComboBox({
fieldLabel:'Items',
store: store,
displayField:'item',
applyTo: 'combo-action',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select an action...',
selectOnFocus:true,
resizable:true,
value: store.getAt(0).get('item'),
listeners:{
select:{
fn:function(combo, record, index) {
var qq= record.get('action').valueOf();
eval(qq+'('+')');
}}
}
});
Cheers,
Vishnupriya
-
1 Jan 2008 11:26 AM #4
Note: Alternative for Remote Data Store
Note: Alternative for Remote Data Store
(Sorry for hijaaking but hopefully this will save others some time)
Note that the solution perscribed above appears to only work for local data stores. If you are retrieving from a database, the store will not be loaded until after a selection is made. Therefore no data will be available to set as default. There are a number of workarounds but, IMHO, the most straight-forward seems to be from Brian.Moeskau...(http://extjs.com/forum/showthread.ph...fault+value%3A).
I've added a slight modification. Since I am returning the data with the default record on top, I always populate the combobox with the first record (ex. combo.setValue(store.getAt(0).get('field to display')); ):
PHP Code:Ext.onReady(function(){
var docStore = new Ext.data.JsonStore({
root: "FacilityDoctors",
fields: ['doctor_id', 'doctor_name'],
url: '../modules/form/getFormElements.php?action=getDoctorCombo'
});
docCombo = new Ext.form.ComboBox({
id:'FacilityDoctors',
store: docStore,
displayField:'doctor_name',
typeAhead: true,
mode: 'remote',
triggerAction: 'all',
emptyText:'Select Doctor...',
selectOnFocus:true,
valueField:'doctor_id'
})
docCombo.applyTo('doctor_id')
docStore.on('load', function(){
docCombo.setValue(docStore.getAt(0).get('doctor_name')); // always default to first record
docCombo.mode = 'local'; // load once and cache
}, this, {single:true}); // single to make sure this is only done on initial load
docStore.load();
});
Why ask why if the answer is never further from the truth?!!


Reply With Quote