PDA

View Full Version : add dynamic options to dropdown



Santosh Dhumale
27 Aug 2012, 10:49 PM
I tried the linked dynamic dropdown using server side code using JSON and its working fine.


Now I am converting my existing project in EXT-JS-4.0 and in existing project I did like

function showitemTypefitting(no){

var select1 = document.getElementById("itemTypefitting"+no);
select1.length = 0;
for(var j=0 ; j < listFittingItemType.length ; j++){

select1.options[select1.length] = new Option(listFittingItemType[j],j);
}

var take = document.getElementById("itemfitting"+no);
var ele = take.options[take.selectedIndex].text;
if(ele=="O'LET"){
ele = "OLET";
}

var select = document.getElementById("itemTypefitting"+no);
for(var i = select.length -1 ; i >=1 ; i--){
if(select.options[i].text.length >= ele.length ){
if(ele == "REDUCER" && select.options[i].text.substr(0,5)=="SWAGE" ){

}else if(select.options[i].text.substr(select.options[i].text.length - ele.length , ele.length) == ele){

}else if(select.options[i].text == "REDUCING COUPLING" && ele == "REDUCER" ){

}else if(select.options[i].text == "REDUCING COUPLING" && ele == "COUPLING"){
select.remove(i);

}else{
select.remove(i);
}
}else{
select.remove(i);
}
}


}

and its working fine.

Explanation :
There are two drodown each dropdown data came from an array.
The above function called onchange event of "itemfitting"+no.


How to do it in extjs.
Please help me to change the store of dropdown at client side.

Thanks in advance.

scottmartin
29 Aug 2012, 10:22 PM
You can add items to the store by creating a listener in load ..



listeners: {
load: function() {
this.insert('modelStatus', {
id_status : 0,
status_name: '-',
id_level: 1
});
}
}


Scott

Santosh Dhumale
6 Sep 2012, 10:53 PM
load not worked for mw.

It is not showing any error.

scottmartin
7 Sep 2012, 4:29 AM
See if this helps: (not sure what you mean by 'mw')



// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
],
listeners: {
load: function(store) {
var newRec = {abbr: 'SS', name: 'SenchaSupport'};
store.insert(0,newRec);
}
}
});

// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody()
});?


Scott

Santosh Dhumale
7 Sep 2012, 4:39 AM
I dont want to do it on store load, when a single row is rendered that time i have to get values from that row add to it an array and after it next row should be rendred.