如何在 extjs 3 网格面板中显示/隐藏列
我有一个网格面板,我需要根据复选框的值在网格面板中显示/隐藏列。如果选中该复选框,我需要在网格中显示列,如果未选中该复选框,我需要隐藏网格中的列。
这是我的代码,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果看一下 ExtJS API,特别是 ColumModel 有一个
setHidden
方法,它会隐藏/显示GridPanel
中的列。您还应该挂钩复选框的
onchange
事件,以便可以显示或隐藏该列if take a look at the ExtJS API, particulary the ColumModel there is a
setHidden
method, it would hide/show a column in aGridPanel
.you should also hook the
onchange
event of your check box so you can show or hide the column在 Ext JS 4.1 中,要隐藏列,可以使用:
看起来 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:
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
您可以使用列标题菜单显示/隐藏列 - 您可以选择要显示的列。无论如何,如果你想显示/隐藏一列,试试这个
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
在 ExtJS 4 中,访问网格面板,然后访问 columns 属性,它是 Column 对象的数组。
从那里您可以使用数组迭代器方法( http://www.diveintojavascript .com/core-javascript-reference/the-array-object )来执行操作。
在下面的示例中,我根据标题名称隐藏和显示一些列,但显然您可以根据任何列属性执行操作。
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.
楼上的回答我觉得都挺好的。
但让我给你一个建议。
1) 在 ExtJS 4.x 中,建议使用 Ext.ComponentQuery`s 方法而不是 Ext.getCmp()
2) 隐藏/show columns of the grid 您可以使用以下代码
或显示
它应该解决隐藏/显示网格中任何列的问题。
这里 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
or to show
It should resolve hiding/showing any column in a grid.
Here grid is your grid , it maybe id or xtype etc.