Search code examples
javascriptextjscomboboxextjs4

ComboBox with anyMatch search in ExtJS


I have a ComboBox with a remote store with local filtering.
Instead of the default filtering, by the first characters like %query, I want to filter with the contains/anyMatch mode like %query%.

I tried to solve this with the answers in the question: ExtJs: Search / Filter within a ComboBox, but it didn't worked.

Code:

var users = Ext.create('Ext.form.ComboBox',{
    displayField : 'userName',
    valueField : 'userName',
    queryMode : 'local',
    typeAhead : true,
    store : Ext.create('Ext.data.Store', {
        model   : 'User',
        proxy       : {
            type    : 'ajax',
            url     : './user/list',
            reader  : {
                type: 'json',
                root: 'data'
            }
        }
    });
});

Thanks!


Solution

  • Just have to add the following code in the Ext.form.field.Combobox. This works in ExtJs 4.1 that doesn't have the anyMatch property.

    listeners   : {
        beforequery: function(record){  
            record.query = new RegExp(record.query, 'i');
            record.forceAll = true;
        }
    }