Tiago Sippert
Tiago Sippert

Reputation: 1332

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!

Upvotes: 2

Views: 13501

Answers (3)

Andre
Andre

Reputation: 475

The modifier g is more important, for a global search. i is only for case insensitive search.

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

Upvotes: 3

Tiago Sippert
Tiago Sippert

Reputation: 1332

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;
    }
}

Upvotes: 7

Greendrake
Greendrake

Reputation: 3734

Use anyMatch config option since Ext 4.2.1. In earlier versions it looks like you'll need to override doQuery method in Ext.form.field.ComboBox just to be able to add that option to the filter instance you'll find in there:

me.activeFilter = new Ext.util.Filter({
    root: 'data',
    anyMatch: true, // <- add this
    property: me.displayField,
    value: queryString
});

Upvotes: 7

Related Questions