【问题标题】:Automatically hide "empty" columns in ExtJS grid Panel在 ExtJS 网格面板中自动隐藏“空”列
【发布时间】:2011-07-17 20:10:14
【问题描述】:

ExtJS Grid 是否有自动隐藏“空”列的插件?

如果底层存储中所有记录的映射字段的值与给定的“空”标准(给定的值或更好的函数)匹配,则应将列视为“空”。

底层存储上的运行时添加/删除/更新操作应相应地隐藏/取消隐藏列。

谢谢!

【问题讨论】:

    标签: grid hide show 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);
    

    【讨论】:

    • 感谢您的回答 :) 我最终自己实现了该插件,因为我需要运行时隐藏/显示,并且我需要它能够快速处理数千行。
    【解决方案2】:

    由于我在任何地方都找不到类似的插件,所以我自己实现了它:)

    代码在此处的 extjs/sencha 论坛上:

    http://www.sencha.com/forum/showthread.php?140685-Grid-Plugin-dynamically-hiding-columns-matching-quot-emptiness-quot-criteria&p=626670#post626670

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-01
      • 2022-01-09
      • 2017-10-18
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      相关资源
      最近更新 更多