Hybrid View

  1. #1
    Ext User
    Join Date
    Jan 2008
    Posts
    9
    Vote Rating
    0
    arjun is on a distinguished road

      0  

    Question 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 !

  2. #2
    Sencha User
    Join Date
    Jan 2008
    Location
    Nice, France
    Posts
    43
    Vote Rating
    0
    manube is on a distinguished road

      0  

    Default


    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!
    ...

  3. #3
    Ext User
    Join Date
    Jan 2008
    Posts
    9
    Vote Rating
    0
    arjun is on a distinguished road

      0  

    Default


    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-->

  4. #4
    Sencha User catacaustic's Avatar
    Join Date
    Jul 2007
    Location
    "A Land Down Under"
    Posts
    618
    Vote Rating
    1
    catacaustic is on a distinguished road

      0  

    Default


    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

  5. #5
    Ext JS Premium Member Charlyva's Avatar
    Join Date
    Dec 2007
    Location
    Austria, St. Pölten
    Posts
    88
    Vote Rating
    0
    Charlyva is on a distinguished road

      0  

    Default


    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

  6. #6
    Ext JS Premium Member jgopireddy's Avatar
    Join Date
    Apr 2010
    Location
    Connecticut
    Posts
    3
    Vote Rating
    0
    jgopireddy is on a distinguished road

      0  

    Thumbs up


    Hi Charlyva ,

    this works great.

    value: fileNameStore.getAt(0).get('value'),