View Full Version : How to restrict data (and use associations)?

15 Aug 2011, 8:12 AM
In Ext 3.x I often needed to restrict the values displayed by one widget based on the value selected in another widget.

For example, imagine one ComboBox that selects a US state, and then a second one that offers the names of some cities in that state. When a state is selected, the city-selector should display only the appropriate values.

In 3.x, I addressed this by having an event handler for the state-selector set a base param in the city-selector to the state value and then trigger a load:

In 4.x it would be nice to be able to use associations and say:


But this obviously isn't possible.

How can/should this problem be approached in 4.x?

17 Aug 2011, 9:33 AM
Given no apparently better option, I have addressed this issue by creating a Store sub-class that monitors a widget and automatically updates itself with data restricted based on the widget value.

Thus, in the fictional example, the "State" ComboBox is backed by a normal Store which loads a list of states. There is a "restricted store" which monitors that ComboBox and loads cities based on the selected state. And there is a "City" ComboBox backed by that "restricted store".

This makes the restrictions work quite transparently for any widgets displaying data from the restricted store. It would be nice if 4.x associations could auto-generate methods to produce such a dynamically-linked store, instead of simply providing a store based on links in a single Model instance. For example:

var cityStore = stateStore.cities(stateComboBox);

Obviously, some widgets will work better as "restricting selectors" than others.