Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs4 Combo's and Stores: Remove filter when queryMode=local?

I'm getting frustrated because my store keeps getting filtered whenever I use it to back a combofield. Is there any way I can disable this?

The Scenario

I have a Store with a data field on it; an array of objects loaded when the store is instantiated. I use this store to drive a bunch of combo's in different areas of my app. Unfortunately, my combos are applying filters on the store, causing other combos using the same store to only display the filtered values later on, not the whole list.

Workarounds

My goofy workaround is to call combo.getStore().clearFilter() after I'm done with the combo, but that's going to get old very quick, and probably introduce a bug somewhere, I'm sure.

If I remove queryMode:'local' from my combo's config, all is well, except that now the handy type-ahead feature no longer works; I'm just shown a list of items in a drop-down that I can't even navigate around my typing letters of matching items. That's worse than a regular html select tag!

Any ideas?

Thanks!

like image 729
John Gordon Avatar asked Oct 23 '22 05:10

John Gordon


2 Answers

You can't do that since the filtering is applied not on the combo but on the store. You could try creating multiple instances of the same store and work with that. Though I don't know if it'll work.

Ext.create('combo', {
      //other config
      store : Ext.create('my.store')
});

It'll work if you make the combo non-editable since no filtering can be applied then. But, as you say, you need the type ahead feature, you'll need to create multiple instances of the store.

like image 54
Varun Achar Avatar answered Oct 31 '22 00:10

Varun Achar


In light of the fact that combos will add filters on the backing store, hence affecting all combos that use the store within my application, I've opted to add an override to the combo class so it will clear the filter on the store when the combo box is destroyed.

Ext.define('MAP.override.Combo', {
    override : 'Ext.form.field.ComboBox',
    initComponent : function()
    {
        this.callParent(arguments);

        this.on('beforedestroy',function(combo){
            if(combo.leaveFilter === true) return;

            console.log('clearing filter on store');
            combo.getStore().clearFilter();
        });
    }
});

it's a bit of a hack, but I do allow for the escape hatch of indicating not to clear the filters, too.

like image 35
John Gordon Avatar answered Oct 31 '22 01:10

John Gordon