How do I set a Ext Grid Filter Default?

extjs, filter, grid

Solution

I realise this is an old question but it took me a while to find a solution, therefore I thought I would share.

1) The filter can be set using the value property in the filter.

filter: {
          type: 'LIST',
          value: ['VALUE TO FILTER']
        }

2) In order to initially filter the data use the filterBy() method in the store. This could be defined in the onRender event handler.

this.getStore().load({
    scope:this,
    callback: function() {
        // filter the store 
        this.getStore().filterBy(function(record, id) {
            // true will display the record, false will not
            return record.data.DATA_TO_FILTER == 'VALUE TO FILTER ';
        });
    }
});

Problem

I have a working sort-able grid using the ext 3.4 grid filter plugin. I would like to default the active column to filter true values. User who needs the inactive records could remove the filter. How do I specify a default filter column and value? Thanks in advance! ``` colModel: new Ext.grid.ColumnModel({ defaults: { sortable: true // How do I specify a default filter value // // Only show active records unless the user changes the filter... }, columns: [{ dataIndex:'f_uid', id:'f_uid', header:'ID', hidden:true }, { dataIndex:'f_name', id:'f_name', header:'Name', }, { xtype:'booleancolumn', dataIndex:'f_active', id:'f_active', header:'Active', filterable:true, trueText:'Active', falseText:'Inactive' }] ```

Original source