PDA

View Full Version : pre select a value in multi select extjs



sabhandari
27 May 2012, 11:23 PM
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:



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

sword-it
28 May 2012, 5:37 AM
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.

sabhandari
28 May 2012, 6:06 AM
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.