-
9 Jan 2008 3:45 AM #1
How do I make a default selection in ComboBox ?
How do I make a default selection in ComboBox ?
Hello people,
Am facing a problem while trying to make a default selection in a ComboBox while loading a page. I mean, I have to make one item as selected, by default, while loading the page. I cant use setValue() method as it can take only Strings and not variables. But based on the back-end value I need to make one of the items in the list as selected by default. How do I do that ? Please help.
Adn this is how my ComboBox looks like:
var fileNameStore = new Ext.data.SimpleStore({
fields: ['value']
});
var newGroupIdNameData = Ext.data.Record.create([
{name: 'value', mapping:'value'}
]);
var fileSelectCombo = new Ext.form.ComboBox({
id: 'fileNameSelect',
store: fileNameStore,
mode: 'local',
editable: false,
valueField: 'value',
displayField: 'value',
typeAhead: true,
triggerAction: 'all',
emptyText: '',
selectOnFocus: true,
width: 150
});
fileSelectCombo.addListener('select', handleFileChange);
Thanks in Advance !
-
9 Jan 2008 3:53 AM #2
Hello,
I think that setting the value attribute will resolve your pb:
Code:var fileSelectCombo = new Ext.form.ComboBox({ id: 'fileNameSelect', value: 'myValue', //which is supposed to be in the available data! ...
-
9 Jan 2008 8:38 PM #3
Hi there,
Thanks for the response, but I guess, you didnt get the question properly (Or I didnt put it in a proper way
).... I can set the value by setValue( String value )... But my problem is I dont know the value here.. Its coming from the back-end bean.. So I have to use a variable, not a static string. How do I do that ?
Thanks,
--Arjun-->
-
9 Jan 2008 10:11 PM #4
You do it using the same setValue () method, and instead of the string you use the name of the variable that you've got the value stored in. As a very quick example...
Code:var fileName = 'file.txt'; comboBox.setValue (fileName);
'Once again, fortune vomits on my eiderdown'
- Edmund Blackadder
-
10 Jan 2008 1:03 AM #5
try the following in the config of your ComboBox:
value: fileNameStore.getAt(0).get('value'),
Think that will solve your problem. For me that works great
Best Regards from Austria.
Mike
-
17 Oct 2011 1:31 PM #6


Reply With Quote