如何设置外部网格过滤器默认值? [英] How do I set a Ext Grid Filter Default?

查看:31
本文介绍了如何设置外部网格过滤器默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 ext 3.4 网格过滤器插件的可排序网格.我想默认活动列来过滤真实值.需要非活动记录的用户可以删除过滤器.如何指定默认筛选列和值?

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?

提前致谢!

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'
    }]

推荐答案

我意识到这是一个老问题,但我花了一段时间才找到解决方案,因此我想我会分享.

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

1) 可以使用过滤器中的 value 属性设置过滤器.

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

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

2) 为了初步过滤数据,请使用 store 中的 filterBy() 方法.这可以在 onRender 事件处理程序中定义.

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

这篇关于如何设置外部网格过滤器默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆