0

Possible Duplicate:
how to show/ hide column in a grid panel

In extjs gridpanel, there is an attribute called : visibleColumns. What I want is this:

someGrid = new Gridpanel({
store: this.someStore,
flex: 1,
if (someCond=true)
visibleColumns:[
col1,col2
]
else
visibleColumns:[
col3,col4
]
});

How to achieve the if (someCond=true) ?

Community
  • 1
  • 1
Victor
  • 16,609
  • 71
  • 229
  • 409

2 Answers2

7

You have to try something like that:

someGrid.getColumnModel().setHidden(0, true);
TheHorse
  • 2,787
  • 1
  • 23
  • 32
  • I am using extjs v4.1. Is this feature deprecated ? What is the alternative to hide colum/group of columns at **runtime**? – subbrl Jun 19 '14 at 07:52
  • 1
    I do it in beforeRender method as: this.columns[idx].hide() or .show() depend what i need (where idx is 0-based index of column to hide/show) – DimmuR Aug 20 '14 at 11:59
5

Depending on your someCond add a hidden attribute to the column configuration:

[{
    // col1
    hidden: !someCond
}, {
    // col2
    hidden: !someCond
}, {
    // col3
    hidden: someCond
}, {
    // col4
    hidden: someCond
}]

Note: Make sure to add hidden attribute to all the columns.

himanshu
  • 2,087
  • 1
  • 13
  • 13
Stefan Gehrig
  • 82,642
  • 24
  • 155
  • 189
  • +1 @himanshu: Why do you say to make sure to add hidden attribute to all the columns? It works even without adding to all the columns. – Harshal Waghmare Sep 25 '12 at 08:46
  • @Harshal I think this has to do with the version of ExtJs you are using. My project was using an older version and hiding columns did not work till I added hidden attribute to all the columns – himanshu Sep 25 '12 at 22:08