以编程方式操作ExtJS 4.2中的列表过滤器

时间:2014-02-18 19:15:02

标签: extjs extjs4 extjs4.2

我在网格上使用了很多FiltersFeatures(ListFilter,DateFilter,StringFilter等)我找不到如何操作这些过滤器。我希望能够“选择”列表中的值,而无需用户进入菜单并单击它。

根据以下评论,我无法访问过滤器本身......

grid.$className
"Ext.grid.Panel"

grid.filters.$className
"Ext.ux.grid.FiltersFeature"

grid.filters.getFilter("status")
undefined

我的网格和列的配置

    var filtersCfg = {
        ftype: 'filters',
        local: false,
        filters: [{
            type: 'string',
            dataIndex: 'service_number'
        }]
    };

    var store = Ext.create('Ext.data.Store', {
        autoLoad: true,
        model: 'Service',
        pageSize: 10,
        proxy: {
            type: 'rest',
            format: 'json',
            url: '/services/list',
            extraParams: {order_id: Ext.get('services-panel').dom.dataset.orderId},
            idParam: 'dw_id',
            reader: {
                type: 'json',
                root: 'services',
                totalProperty: 'totalCount'
            }
        },
        remoteSort: true
    });

    grid = Ext.create('Ext.grid.Panel', {
        header: false,
        features: [filtersCfg],
        id: 'gridPanel',
        height: 335,
        frame: true,
        title: 'Services',
        store: store,
        bbar: Ext.create('Ext.PagingToolbar', {
            store: store,
            displayInfo: true,
            displayMsg: 'Displaying services {0} - {1} of {2}',
            emptyMsg: "No services to display"
        }),            
        columns: [{
            header: 'Service #',
            locked: true,
            width: 85,
            sortable: true,
            dataIndex: 'service_number',
            renderer: function(value, meta, record){
                return '<a href="/services/' + record.data.dw_id + '">' +  value + '</a>';
            }
        }, {
            header: '',
            locked: true,
            width: 35,
            sortable: true,
            dataIndex: 'is_monitored',
            renderer: function(value, meta, record){
                if(value){return '<span class="glyphicon glyphicon-stats"></span>';}
            }
        }, {
            header: 'Status',
            width: 100,
            sortable: true,
            dataIndex: 'status',
            filter: {
                type: 'list',
                id: 'status_list',
                options: [<%= Service.uniq.pluck(:status).collect(&:to_json).sort.join(",") %>]
            }...

1 个答案:

答案 0 :(得分:0)

假设您使用FiltersFeature的网格为grid

grid.filters.getFilter(dataIndexForFilterYouWant).setValue(newValue);

同样,您可以使用getValue获取过滤器的值,或使用setActive使过滤器处于活动或非活动状态。有关FiltersFeature的更多信息,请查看文档:{​​{3}}

或有关过滤器本身的更多信息:http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.ux.grid.FiltersFeature