View Full Version : Load ComboBox Store From Local Store By Using Collect and Filter

24 Sep 2013, 1:58 PM
*** ExtJS 4.0.7 ***

I have an application wide store that is initially loaded from an ajax request. This store contains several fields. The "unique" values of these fields are to be used as values in a combo box. I see that I can use the collect method to return unique values in a store. However, I need that collect method to adhere to a filter based on other combo boxes.

So for example, the store contains a set of purchase order records with customer information. So as you can imagine, you're going to have po#, line#, customer number, customer name, item#, item desc, etc etc. If I wanted to see a list of records for a specific customer for a specific item#, I would use two combo boxes to filter the list: customer_number_combo, item_number_combo. However, when I select the customer_number_combo value, i want the item_number_combo to return a list of item numbers from the application wide store for that customer number. I hope this makes sense.

24 Sep 2013, 9:51 PM
Why you don't bind combo to that store?

25 Sep 2013, 6:07 AM
I guess I could if I knew what that was.

However, beyond "What could I do", is there a way to do it how I suggested?

25 Sep 2013, 7:21 AM
I just Googled your suggestion. It seems that "binding" a store to a combo box is simply specifying the store config on the combo box. I've actually already done that part. However, I need to be able to get distinct values from the "global" store and filter those results based off other values in the store. I'm not sure how "binding" solves the problem.

27 Sep 2013, 11:32 AM
Unfortunately Google doesn't index the docs webapp. :)
If you configure storeId (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.AbstractStore-cfg-storeId) for your 'Global' store, you can specify it for combos (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.ComboBox-cfg-store).

With approach in first message you will need to create instances of some custom store class (of course, it needs to be defined first), that will somehow sync their data with global's data.

27 Sep 2013, 12:00 PM
I am interpreting your response as if we are saying the same thing. My combos are already using the global store. I am currently getting distinct values from the global store by using the collect method. However, I need to be able to "filter" which "unique" records to include in my combo. Let's say the global store has:


My PARTSTATUS combo will have unique values of 'I' and 'A' (inactive and active). When I select PARTSTATUS = 'I', my PARTNUMBER combo should only have those parts from the global store that have PARTSTATUS = 'A'.

Hopefully that makes sense. I need to know how to perform a collect AND filter which collected records are put into the PARTNUMBER combo. Hopefully that makes sense.

30 Sep 2013, 3:54 AM
Yes, I've mistakenly understood your requirement.
Well, then you will need two more stores, that will hold those unique values. You can either update the sets they contain manually, or make them listening to some events (maybe just 'datachanged') from your 'Global'.

3 Oct 2013, 6:12 PM
Sorry to keep posting on this, but I'm still looking for some sort of array method or store method that will allow me to get distinct values and filter those values based off other values within a local store.

So if you have itemStatus and itemNumber, and you select itemStatus, I only want itemNumber that have that status. Keeping in mind, that there will be duplicate itemNumber s in the local store.

I do realize that ettavolt gave "a" solution, and I do appreciate that, but something is telling me there is a more native/natural solution (a combination of collect() and filter).

To make the example more clearer, I want to return the following results from within the web page (no Ajax requests):

select distinct(itemNumber)
from global_store
where itemStatus = 'Y'