2011-07-15 84 views
1

ExtJS網格是否有插件可自動隱藏「空」列?自動隱藏ExtJS網格面板中的「空」列

如果底層存儲區中所有記錄的映射字段的值與給定的「空白」條件(給定值或更好的函數)匹配,則該列應被視爲「空」。

底層商店的運行時添加/刪除/更新操作應相應地隱藏/取消隱藏列。

謝謝!

回答

1

我不得不做類似這樣的事......這裏是一個「隱藏列模型」,它將根據「fieldHasData」方法的返回值來隱藏/顯示列......它可能是一個緊密的開始什麼你問

Ext.ux.grid.HidingColumnModel = function() { 

    var Class = Ext.extend(Ext.grid.ColumnModel, {   
     constructor:function(config) { 
      Class.superclass.constructor.call(this, config); 
     }, 

     onGridStoreLoad:function(store, records, options) { 
      store.fields.each(function(item, index, length) { 
       var colIndex = this.findColumnIndex(item.name); 
       if (colIndex >= 0) { 
        this.setHidden(colIndex, !this.fieldHasData(item.name, records)); 
       } 
      }, this); 
     }, 

     fieldHasData:function(field, records) { 
      var hasData = false; 
      Ext.each(Ext.pluck(records, "data"), function(item, index, allItems) { 
       if (item[field]) { 
        hasData = true; 
       } 
      }); 
      return hasData; 
     } 
    }); 

    return Class; 
}(); 

,然後在網格......你添加的列模型

var columnModel = new Ext.ux.grid.HidingColumnModel(), 
    store = ... {create your store}, 
    gridPanel = new Ext.grid.GridPanel({ 
     ... 
     store:store, 
     columnModel:columnModel, 
     ... 
    }); 

store.on('load', columnModel.onGridStoreLoad, columnModel); 
+0

謝謝您的回答:)我最終實現了自己的插件,因爲我需要運行時隱藏/顯示,我需要它要快與成千上萬的行。 – Sergio