PDA

View Full Version : multiple comboboxes that share one store



optibase
20 Dec 2010, 7:16 AM
Hi
I asked a similar question before but didnot get an answer that worked form me so I will try to asked it differently..
:)

I need to populate a set of combo boxes (possibly in a formpanel) from a single jsonstore and if possible , do so while using the extjs designer .just can't figure out how to do it.

I need all combos to be populate each with it's own data from that store, and I need that upon submit the whole store will be set to reflect the new values of all comboboxes so that I can update the server.

an example json would look something like that:

{ "MyComboboxesOneStore" : { "combo1" : [ { "name" : "value1_1" },
{ "name" : "value1_2" },
{ "name" : "value1_3" }
],
"combo2" : [ { "name" : "value2_1" },
{ "name" : "value2_2" },
{ "name" : "value2_3" }
]
} }

Hope someone can help me out here
thanks a lot

jarrednicholls
20 Dec 2010, 7:28 AM
Hi optibase, this might be more suitable in the Ext: Help forum. I'll move it there for you. You might need to provide more information, such as how the data is separated in the store for each ComboBox. For updating the values, you will need to update the records in the store directly as the ComboBox values change (see the select (http://dev.sencha.com/deploy/dev/docs/?class=Ext.form.ComboBox&member=select) event from ComboBox as one avenue).

optibase
20 Dec 2010, 7:37 AM
Thanks :)

It is pretty much up to me how the separations between comboboxes is set.. as i tried to show in the small json example i could just use different elements in the store as combo1{....}, combo1{..} and have each combobox reader read it's own sections but I am not sure who to put it together.

Condor
20 Dec 2010, 7:42 AM
Are you looking for:

store1.load({
callback: function(){
store2.loadData(store1.reader.jsonData);
store3.loadData(store1.reader.jsonData);
store4.loadData(store1.reader.jsonData);
}
});

optibase
20 Dec 2010, 7:59 AM
Are you looking for:

store1.load({
callback: function(){
store2.loadData(store1.reader.jsonData);
store3.loadData(store1.reader.jsonData);
store4.loadData(store1.reader.jsonData);
}
});

Hi and thanks for the fast reply :)

I have seen this code in one of the thread..

I must admit to being guilty of being a complete newby to extjs so some thing are not clear to me:

Asuming store1 calls a PHP routine that returns a JSON with all combos data. What are the store2 and store3? are they loclal in-memory stores that are getting loaded from store1, but never goes to the server?

more..
how sould I build the JSON ? should it be like as in my example above and setting the root of each combobox to it's corresponding section?

and last..

will store1 auto update when the children comboboxes made a selection, or should I catch the select event on the children and update store1 myself so that upon submit the full store will update the server?

oh boy i hope I make sence:s

thanks so much

Condor
20 Dec 2010, 8:17 AM
1. store1-3 are the stores of the comboboxes. You only load one, and with the returned server data (of which the first store only used part) load the other stores.

2. Yes, your server data should have a different root for each store you want to load.

3. Could you try to explain a bit better?

Particularly this:

... I need that upon submit the whole store will be set to reflect the new values of all comboboxes so that I can update the server.
and this:

... will store1 auto update when the children comboboxes made a selection, or should I catch the select event on the children and update store1 myself so that upon submit the full store will update the server?

optibase
20 Dec 2010, 8:59 AM
Condor,
Thanks so much.

If I understand your suggestion, then asuming I have 30 combos in a form I will end up with 30(31) stores.
All stores will derives it's data from the main store, the one that actualy made the call to PHP.

After my page was loaded and the user selects values on some of the camobs I need to update the server. I want to make 1 call to the PHP routine ,just like when loading the data.

How can I have my "main" store updated at all time so that I can submit all changes with one call, should I manualy update that "main" store on each select of any combo box? or is there away to have my30 stores update the "parent" store when a selection is made.

Hopefully i made more sence now..

Thanks A lot again

Condor
20 Dec 2010, 11:23 AM
I don't understand. These stores are the combobox list source. They don't hold the combobox value that you want to send back to the server.

optibase
26 Dec 2010, 10:21 AM
Hi Condor
Thanks for clearing this for me :)

aman.gupta
28 Jul 2014, 11:56 PM
Are you looking for:

store1.load({
callback: function(){
store2.loadData(store1.reader.jsonData);
store3.loadData(store1.reader.jsonData);
store4.loadData(store1.reader.jsonData);
}
});

Yup.. Thanks :) btw, what is nice way to get reference of callback outside store ? I have heard about promises, but dnt know its implementation.

I mean something like this:


var records = store.load(function(records, operation, success){
return records; // I want this to access outside
});
console.log(records); // but it won't work as callback will respond afterward