1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    8
    Vote Rating
    0
    sabhandari is on a distinguished road

      0  

    Default pre select a value in multi select extjs

    pre select a value in multi select extjs


    Hi,

    I want a particular value to be pre-selected in the multi-select box and also fire the listener attached with the multi-select for the first time .

    Please see the code below:

    Code:
                
            var trainStore = new Ext.data.ArrayStore({
                type: 'ajax',
                url:'<URL which returns JSON array>',
                autoLoad:true,
                fields: ['text', 'value']
            });
     var selectTrain = [{
                bodyStyle: 'padding:10px;',
                items:[{
                    xtype: 'multiselect',
                    title: 'Select Train(s)',
                    name: 'selectTrain',
                    width: 250,
                    height: 200,
                    id: 'selectTrain',
                    hidden:true,
                    store: trainStore,
                    displayField:'value',
                    valueField:'text',
                    ddReorder: true,
                    listeners : {
                           click : function(combo){
                                   if(this.getValue() == "All") {
                                       var records = trainStore.getRange();
                                       for (var i = 1; i < records.length; i++) {
                                           selectedTrain += records[i].data.text + ",";
                                       }
                                       selectedTrain = selectedTrain.substring(selectedTrain,selectedTrain.length-1);
                                  } else {
                                       selectedTrain = this.getValue();
                                   }
                                releaseStore.load({params:{relNoId: selectedTrain}});
                            }
                    }
                }],
                buttons: [{
                    text: 'Go',
                    id: 'trainGoButton',
                    hidden:true,
                    handler: function(){
                            releaseStore.load({params:{relNoId: selectedTrain}});
                            Ext.getCmp('selectRelease').show();
                            this.hide();
                            Ext.getCmp('releaseGoButton').show();
                    }
                }]
    
            }];
    Pls advise.

    Regards

  2. #2
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default check the value in afterrender

    check the value in afterrender


    Hi,

    If your multiselect is not populated with an ajax call or something asynchronous with the rendering process, you can check the value in afterrender listener and do the same process.

    If so, please provide a code sample about what is multiselect written in your 3.x code, about how a value can be set etc. so that we can catch the time when the initial value is set.

    Regards.
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    8
    Vote Rating
    0
    sabhandari is on a distinguished road

      0  

    Default


    No the data is not static and is received asynchronously from servlet and this asynchronous call happens on Ext.onReady. Can I select the first element in the multi-select and then also invoke the click/select listener attached to the multi-select component.

    The code is shown above in my post.

Thread Participants: 1

Tags for this Thread