Extjs Grid panel - Hide a column with hideable=false

只愿长相守 提交于 2019-12-11 11:14:17

问题


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...


回答1:


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.




回答2:


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

This will work on Ext js 4.1


回答3:


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




回答4:


Reconfigure the grid for each scenario. Link to api hint




回答5:


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



来源:https://stackoverflow.com/questions/12950428/extjs-grid-panel-hide-a-column-with-hideable-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!