1
votes

i'm using Extjs 4.1 grid panel.

i'm looking for a way to hide a column from the grid. i can use setHidden but then the user can "unhide" the column again from the menu in the column header. it seems that the hideable propery just doesnt cut it...

5

5 Answers

1
votes

Ok. Eventually i did this: in the grid's "afterrender" event:

var header = pnl.down("headercontainer");
if(header != null && header["getMenu"] != null)
{
   var menu=header.getMenu();
   menu.on('beforeshow',function(sender,eOpts){

            var menu=sender;
            if(!menu.items.containsKey("columnItem"))
            {
                return;
            }

            var columnsSubMenuItem=menu.items.getByKey("columnItem");
            var columnsCheckboxes=columnsSubMenuItem.menu.items["items"];

            // More code here...
            // See the pseudo code
   });
}

now i just looped through the columns and if checkbox.text == column.get_Title() && column.get_Hideable() == true then checkbox.Show() else checkbox.Hide();

(sorry for the pseudo code, i work with a Sharpkit that is a C# to javascript convertor, so if i'd copy pasted the code it'd be harder to explain.

Note: you can do the same with the grid's enableColumnHide event.

1
votes

use following config to column

hidden: true, hideable: false

'grid.headerCt.getGridColumns()'

use above method to get all grid column and use hide() and show() to show particular column

0
votes

You can configure columns property in initComponent method and insert only necessary columns into this.columns array

0
votes

Reconfigure the grid for each scenario. Link to api hint

0
votes

I use the setVisible(false | true) on the column. doc