View Full Version : Removing a store from a combobox

8 Jul 2015, 5:28 AM
What is the correct way to "empty" a combo (ie remove its' list of values) without affecting the store?

combo.bindStore(null) does not work-- it causes exceptions. See this fiddle for an example:

I know I can achieve this by removing all items from the store but I don't want to do this-- the store is shared throughout the application, it cannot be modified.

For a use-case, assume I have 2 combos, "Country" and "State". If user deselects a country, the state combo must become unusable-- it has no selectable values.

8 Jul 2015, 5:44 AM
You can just create another empty store with the same fields and bind your combo to that.


8 Jul 2015, 7:49 AM
That is true (that is what I am doing now, temporarily), but it seems to me like it is unnecessary overhead.

8 Jul 2015, 8:36 AM
You cannot be using the same store for the combo that is being shared across the application. At the very least you would need to clone the global store by defining the store once and using one instance of it globally and one specifically for the combo. Then listen to any change in the global store and reflect it in the combo store.

8 Jul 2015, 10:38 AM
Couldn't you just disable the combobox instead?

There's an empty store created by the framework with the id ext-empty-store, you could use that if you're trying to avoid creating new stores. See the source for Ext.data.Store to see where that's created.

You cannot be using the same store for the combo that is being shared across the application.

In general sharing a store doesn't work but if the store is preloaded and you disable all filtering (i.e. editable: false) then you can get away with sharing the store.

9 Jul 2015, 5:30 AM
I reuse the store not on the same page, but in various places throughout the user's browsing of the application (which is quite large), not always in a combo. Basically we load this information once (yes it is preloaded) and display it as necessary. Periodically we reload it. I've never had issues with this setup, we use it extensively. I can't remember how it behaves if we use the same store twice at the same time, maybe we do clone it in that rare case.

And yes, the store is read-only, if I need to filter it I clone it, but this is a rare case.

Thanks for letting me know about ext-empty-store Skirtle, this is probably what I will end up using. I was hoping there was some way to just not set a store, but it looks like there is not.

Unfortunately disabling the combo is against business/ux requirements.