Search code examples
filterextjs4.2separator

Extjs4.2 filter on one column and user can use separator to match different rows


I have to filter on one column, and user can use separator to match different rows, like this: (As I couldn't post images, I have to describle the menuitme for my column)

Sort Ascending
Sort Descending
Filters =>  Jim|Tom

User could enter "Jim|Tom" in the Textbox to filter on the Grid.

But Generally, it seems not supported by Extjs 4.2. I found that apply multiple values for one property does not work like above.

Here is my column definition for this column 'Owner':

{   
    text:'Owner',
    width:50,
    dataIndex:'owner',
    sortable:true,
    filter:{
    type:'string',
    }
},

How could I solver this problem?

Thanks.

Alex


Solution

  • You would need to override string filter, something like (untested):

    Ext.define('MyOverride', {
       override: 'Ext.ux.grid.filter.StringFilter',
    
        validateRecord : function (record) {
            var val = record.get(this.dataIndex);
    
            if(typeof val != 'string') {
                return (this.getValue().length === 0);
            }
            val = val.toLowerCase();
            var parts = this.getValue().toLowerCase().split('|'),
                found = false;
    
            Ext.Array.forEach(parts, function(part) {
                if (val.indexOf(part) > -1) {
                    found = true;
                }
            });
    
            return found;
        }
    });