在运行时隐藏Grid中的列

时间:2016-03-23 19:57:39

标签: extjs6 extjs6-classic

我在运行时隐藏Grid中的列时遇到了麻烦。

在一个项目中,我使用一个返回Grid中列的配置的函数。 为了获取Grid中列的列表,我使用这段代码:

  

var cmV = cmpGrid.getView();   var cmH = cmV.getHeaderCt();   var cm = cmH.getGridColumns();

变量" cm"返回一个数组,其中包含网格中已配置的列。

当我使用"列"手动隐藏列时使用ExtJS版本3.4.1的标题网格中的选项我可以获得属性

  

hidden:true

用于配置的列。 但是使用ExtJS 6时,配置的列不包含此属性。

我如何解决这个问题?

提前谢谢, 洛伦佐。

**

更新

** 我已经发现了关于我之前的问题。 与

  

var cm = cmH.getGridColumns();

我可以获取网格中的列数组。 用Firebug分析这个数组我找到了子阵列" config"包含配置列所需的属性。 但是现在这个数组并没有反映更改列的更改配置,但应用了默认配置。 我的第一个问题是这个新行为是否是一个错误。 因为我发现了这个新行为,所以我更改了代码以获取列的属性,而不是从子数组配置而是从基数。然而,现在可能的配置是如此之多。 现在我的第二个问题是,是否有办法减少或只有网格中列类型的主要属性。

1 个答案:

答案 0 :(得分:0)

为什么不使用grid.columns[index].setHidden(true)

或者,如果您想获取列列表,请重新配置列。

var tempColumns = [];

// "cm" returns an array with the configured columns in the grid
cm.forEach(function(e) {
    if (some conditions) {
        tempColumns.push({
            xtype: e.xtype,
            text: e.text,
            dataIndex: e.dataIndex,
            hidden: true,
            width: e.width,
            align: e.align,
            format: e.format
        });
    }
    else{
        tempColumns.push({
            xtype: e.xtype,
            text: e.text,
            dataIndex: e.dataIndex,
            hidden: e.hidden,
            width: e.width,
            align: e.align,
            format: e.format
        });
    }
});

grid.reconfigre(null, tempColumns);

https://fiddle.sencha.com/#fiddle/17lq

相关问题