如何处理检查和取消选中extjs中存储的复选框字段

时间:2012-11-14 21:28:20

标签: extjs checkbox filter store extjs4.1

我有一个商店,可以加载一个显示州名,资本和寒冷天气的网格。

我还有一个复选框,根据“寒冷天气”列的“是”值过滤商店。

当我单击复选框时,网格会过滤并显示“是”的状态,但是当我取消选中该复选框时,它什么都不做。

如何恢复商店以显示以前的商店?下面是我的复选框。请帮忙。

items: [
    {
        xtype: 'checkboxfield',
        boxLabel: 'Show only Cold State',
        scope: this,
        handler: function (field, value) {
            scope: this,
            this.checkValue = field.getValue();
            console.log(this.checkValue);
            if (this.checkValue == true) {
                this.store.filter('Cold', 'Yes');
            }
            else if (this.checkValue == false) {
            }
        },

更新代码 - 当我这样做时,我收到此错误

  

TypeError:tempstore1未定义

items: [
    {
        xtype: 'checkboxfield',
        boxLabel: 'Show only Cold State',
        scope: this,
        handler: function (field, value) {
            scope: this,
            this.checkValue = field.getValue();
            console.log(this.checkValue);
            if (this.checkValue == true) {
                var tempstore1 = Ext.StoreMgr.lookup('store');
                tempstore1.filters.add('CheckBoxFilter', new Ext.util.Filter({
                    property: 'Cold',
                    value: 'Yes',
                    root: 'myTable'
                }));
                console.log('here');
                tempstore1.load();
            }
            else if (this.checkValue == false) {
                this.store.filters.removeAtKey('CheckBoxFilter');
            }
        },

第二次更新 - 现在我收到此错误

  

TypeError:a.getRoot.call(a,d)未定义

而不是

var tempstore1 = Ext.StoreMgr.lookup('store');

我正在使用

var tempstore1 = Ext.getCmp('GridArea1').store;

GridArea1是我的网格面板的ID。

第三次更新 - 现在我用

收到此错误
var tempstore1 = Ext.getCmp('GridArea1').getStore();
来自chrome调试器的

错误...“true”和“here”是我的console.log,所以是“h”部分......这就是tempstore1而不是我的数据..

  


  h {hasListeners:e,范围:h,loading:false,events:Object,eventsSuspended:false ...}
  这里
  未捕获的TypeError:无法读取未定义的属性“冷”

1 个答案:

答案 0 :(得分:5)

您需要使用clearFilter()

xtype: 'checkboxfield',
boxLabel: 'Show only Cold State',
scope: this,
handler: function (field, value) {
    scope: this,
    this.checkValue = field.getValue();
    console.log(this.checkValue);
    if (this.checkValue == true) {
        this.store.filter('Cold', 'Yes');
    }
    else if (this.checkValue == false) {
        this.store.clearFilter();
    }

可以删除特定的过滤器(clearFilter()将其全部删除)。不使用store.filter('property_to_filter','value')方法,而是使用:

store.filters.add('Coldfilter', new Ext.util.Filter({
    property: 'Cold',
    value: 'Yes',
    root: 'data'
});
store.load();

要删除过滤器,请使用:

store.filters.removeAtKey('Coldfilter');

有关root: 'data'的文档中没有任何内容可以添加到过滤器中,现在它可以正常运行:http://jsfiddle.net/vrVRP/2/