tags:

views:

3350

answers:

3

I have a grid panel i need to show / hide columns in a gris panel depending on the value of a checkbox.If the checkbox is cheked i ned to diaplay 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 iam not able to toggle the columns depending on the value of the checkbox. But when i login and log out iam able to see the changes in the grid panel.Can anyone help me in refreshing the column values in the grid panel?

+4  A: 

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

RageZ
Checkbox is in another page to which a flag is set and depending on the value of the flag column in the grid panel is visible or hidden.It is working perfect now.Thanks for the reply.
XRX215
+1  A: 

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);
Igor Pavelek
Thanks. It is working now :)
XRX215
A: 

what if i want to hide a column and make sure its always hidden

for example, i hide it with this code, but clicking on the header i get the chance to make it visible again. i want to hide the id columns and make sure never visible for the user but still there for the script to work with it ?

GumaTerror
Remove it from column model all together. The data is in the grid's store for you to work with.
Mchl