PDA

View Full Version : on selecting an item from combobox, load the store of another combox with a param



vick_44
6 Sep 2016, 7:50 AM
I have below two comboboxes,


state |----------| percentage |------------|


once i select an item from state drop down list, i need to load the store of 'percentage' combobox with the argument for rest call as the state selection done earlier.


for example


state:
> AL
> NJ
> MN
> LA


I chose "LA",
as soon as i select LA in state, it needs to call percentage combobox's store.load with parameter as "LA"


my current percentage model is as below for


store: XXXXXXX.store.search.PercentageStore









Ext.define('XXXXXXX.model.search.PercentageModel',{
extend :'Ext.data.Model',
fields:[
//below needs to be changed once column names are decided
{name: 'description' , type: 'string'}
],
autoLoad:true,

proxy: {
type: 'rest',
headers : {
'Accept' : 'application/json'
},
reader: {
type: 'json',
root: 'data',
totalProperty: 'totalproperty',
successProperty: 'success'},
writer: {
writeAllFields: true,
nameProperty: 'name',
type: 'json'
},
url: '/XXXXXXX/search/getPercentageBasedOnState'
}


});


And my listener for 'state' select is as below which, as of now, is just populating another text box with the webservice result. But now i need to call another store in this same event listener which will call the store load by passing the selected state as argument.




stateOnSelect:function(item){
me=this;
Ext.Ajax.request({
url: '/XXXXXXX/search/getRegionByState',
method: 'GET',
params: {
state: item.value
},
success: function(response){
var data = Ext.JSON.decode(response.responseText);
me.getSearchForm().getForm().findField('region').setValue(data.data);
}
});
}


I tried adding the below lines but it doesnt seem to work.



perStore = Ext.data.StoreManager.lookup('XXXXXXX.store.search.PercentageStore');
perStore.getProxy().extraParams = { state:item.value};
perStore.load();

any help is deeply appreciated.

vick_44
6 Sep 2016, 8:46 AM
please Ignore the question. I solved this by adding below lines in my listener


perStore = Ext.data.StoreManager.lookup('XXXXXXX.store.search.PercentageStore');
perStore .load({params: {state: item.value}});

Gary Schlosberg
6 Sep 2016, 3:14 PM
Glad to hear that you've found a solution, and thanks for sharing it with the community.