2012-11-14 40 views
1

我有一個商店,加載顯示國家名稱,大寫和寒冷天氣的網格。如何處理檢查和取消選中複選框字段存儲在extjs

我也有一個複選框,根據「寒冷天氣」欄的Yes值過濾商店。

當我點擊複選框時,網格會過濾並顯示具有'是'的狀態,但是當我取消選中該複選框時,它不執行任何操作。

如何恢復店面以顯示以前的店鋪?以下是我的複選框字段。請幫忙。

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 is undefined

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

月2日更新 - 現在我得到這個錯誤

TypeError: a.getRoot.call(a, d) is undefined

代替

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

我使用

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

GridArea1是我的GridPanel的ID。

3日更新 - 現在我得到這個錯誤與鉻調試

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

錯誤......「真」和「這裏」是我的console.log,所以是「H」的一部分。 ..這是什麼tempstore1擁有的,而不是我的數據..

true
h {hasListeners: e, scope: h, loading: false, events: Object, eventsSuspended: false…}
here
Uncaught TypeError: Cannot read property 'Cold' of undefined

回答

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.filters.add('Coldfilter', new Ext.util.Filter({ 
    property: 'Cold', 
    value: 'Yes', 
    root: 'data' 
}); 
store.load(); 

要刪除過濾器,使用::除了使用store.filter('property_to_filter','value')方法,使用

store.filters.removeAtKey('Coldfilter'); 

中沒有任何關於root: 'data'在過濾器中添加的文檔,現在它的工作原理:http://jsfiddle.net/vrVRP/2/

+0

感謝您的答案Pheonix,但這會清除我以前的過濾器。我不想清除之前的過濾器。前面的過濾器是由一個組合框觸發的,我在這裏沒有提到。無論如何,你的靈魂會更容易,但我試圖回到之前的過濾器,然後點擊複選框。 – EagleFox

+0

@EagleFox更新了答案。 – Pheonix

+0

THanks Pheonix ...我試圖實現你的答案,但得到「預期」,「」錯誤......我可以在處理程序中執行它還是應該創建函數 – EagleFox

相關問題