如何在 extjs 3 网格面板中显示/隐藏列

发布于 2024-08-12 02:02:19 字数 611 浏览 5 评论 0原文

我有一个网格面板,我需要根据复选框的值在网格面板中显示/隐藏列。如果选中该复选框,我需要在网格中显示列,如果未选中该复选框,我需要隐藏网格中的列。

这是我的代码,

var chkEnableDisplayResponsibilityForAction = '<%=Session["chkEnableDisplayResponsibilityForAction"]%>';

 var flags = Boolean.parse(chkEnableDisplayResponsibilityForAction);
 var flags1 = !Boolean.parse(chkEnableDisplayResponsibilityForAction)

 var colModel = new Ext.grid.ColumnModel([
 { header: "PricePlanID", width: 100, sortable: true, dataIndex: 'PricePlanID', hidden: flags, hideable: flags1 },
  ]);  

当我刷新页面时,我无法根据复选框的值切换列。但是当我登录和注销时,我可以看到网格面板中的更改。谁能帮我刷新网格面板中的列值?

I have a grid panel i need to show / hide columns in a grid panel depending on the value of a checkbox. If the checkbox is checked i need to display column in the grid and if it is unchecked i need to hide the column in the grid.

Here is my code

var chkEnableDisplayResponsibilityForAction = '<%=Session["chkEnableDisplayResponsibilityForAction"]%>';

 var flags = Boolean.parse(chkEnableDisplayResponsibilityForAction);
 var flags1 = !Boolean.parse(chkEnableDisplayResponsibilityForAction)

 var colModel = new Ext.grid.ColumnModel([
 { header: "PricePlanID", width: 100, sortable: true, dataIndex: 'PricePlanID', hidden: flags, hideable: flags1 },
  ]);  

when i refresh the page i am not able to toggle the columns depending on the value of the checkbox. But when i login and log out i am able to see the changes in the grid panel. Can anyone help me in refreshing the column values in the grid panel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

情痴 2024-08-19 02:02:19

如果看一下 ExtJS API,特别是 ColumModel 有一个 setHidden 方法,它会隐藏/显示 GridPanel 中的列。

myGrid.getColumnModel().setHidden(0, true);

您还应该挂钩复选框的 onchange 事件,以便可以显示或隐藏该列

if take a look at the ExtJS API, particulary the ColumModel there is a setHidden method, it would hide/show a column in a GridPanel.

myGrid.getColumnModel().setHidden(0, true);

you should also hook the onchange event of your check box so you can show or hide the column

Bonjour°[大白 2024-08-19 02:02:19

在 Ext JS 4.1 中,要隐藏列,可以使用:

grid.columns[0].setVisible(false);

看起来 getColumnModel() 及其 setHidden() 方法不再是网格的一部分:
https://docs.sencha.com/extjs /4.1.0/#!/api/Ext.grid.Panel

In Ext JS 4.1, to hide a column, you use:

grid.columns[0].setVisible(false);

Looks like getColumnModel() with its setHidden() method is no longer part of the grid:
https://docs.sencha.com/extjs/4.1.0/#!/api/Ext.grid.Panel

吃颗糖壮壮胆 2024-08-19 02:02:19

您可以使用列标题菜单显示/隐藏列 - 您可以选择要显示的列。无论如何,如果你想显示/隐藏一列,试试这个

myGrid.getColumnModel().setHidden(0, true);

You can show/hide columns using column header menu - you can choose which column you want to have shown. Anyway, if you want to show/hide a column, try this

myGrid.getColumnModel().setHidden(0, true);
葬花如无物 2024-08-19 02:02:19

在 ExtJS 4 中,访问网格面板,然后访问 columns 属性,它是 Column 对象的数组。

从那里您可以使用数组迭代器方法( http://www.diveintojavascript .com/core-javascript-reference/the-array-object )来执行操作。

在下面的示例中,我根据标题名称隐藏和显示一些列,但显然您可以根据任何列属性执行操作。

var grid = Ext.getCmp( 'my_grid_panel' );

grid.columns.forEach( function( col ) {
   if( ( col.text == "Foo" ) || ( col.text == "Bar" ) ) {
      col.setVisible( true );
   } else if( col.text == "Baz" ) {
      col.setVisible( false );
   }
});

In ExtJS 4 gain access to your grid panel, and then access the columns attribute which is an array of Column objects.

From there you can use the array iterator methods ( http://www.diveintojavascript.com/core-javascript-reference/the-array-object ) to perform an action.

In the below example I hide and show a few of the columns based on their header names, but you can obviously perform action based on any Column attribute.

var grid = Ext.getCmp( 'my_grid_panel' );

grid.columns.forEach( function( col ) {
   if( ( col.text == "Foo" ) || ( col.text == "Bar" ) ) {
      col.setVisible( true );
   } else if( col.text == "Baz" ) {
      col.setVisible( false );
   }
});
执妄 2024-08-19 02:02:19

楼上的回答我觉得都挺好的。
但让我给你一个建议。

1) 在 ExtJS 4.x 中,建议使用 Ext.ComponentQuery`s 方法而不是 Ext.getCmp()

2) 隐藏/show columns of the grid 您可以使用以下代码

Ext.ComponentQuery.query('grid gridcolumn[dataIndex^="service"]')[0].hide()

或显示

Ext.ComponentQuery.query('grid gridcolumn[dataIndex^="service"]')[0].show()

它应该解决隐藏/显示网格中任何列的问题。

这里 grid 是你的网格,它可能是 id 或 xtype 等。

The answers above I think are pretty good.
But let me give you a advice.

1) In ExtJS 4.x it is recommended to use Ext.ComponentQuery`s methods instead of Ext.getCmp()

2) To hide/show columns of the grid you can use following code

Ext.ComponentQuery.query('grid gridcolumn[dataIndex^="service"]')[0].hide()

or to show

Ext.ComponentQuery.query('grid gridcolumn[dataIndex^="service"]')[0].show()

It should resolve hiding/showing any column in a grid.

Here grid is your grid , it maybe id or xtype etc.

寄离 2024-08-19 02:02:19
setVisibleColumn       : function(name, flag) {
    name = Ext.Array.from(name);
    var column;

    for (var i = 0; i < name.length; i++) {
        column = this.getColumn(name[i]);
        if (column) {
            flag ? column.show() : column.hide();
        }
    }

}
setVisibleColumn       : function(name, flag) {
    name = Ext.Array.from(name);
    var column;

    for (var i = 0; i < name.length; i++) {
        column = this.getColumn(name[i]);
        if (column) {
            flag ? column.show() : column.hide();
        }
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文