欢迎访问中国最大的EXTJS讨论社区 首页 论坛 教程

Ext教程-一起Ext

当前位置: 首页 > 教程 > Ext Grid >

Ext.grid.GridView禁止隐藏列代码

时间:2009-04-12 22:24来源:未知 作者:admin 点击:
默认的grid是允许用户隐藏列的,下面的代码将此功能禁用了,有时候会用到! if(g.enableColumnHide !== false){ if (this.cm.config.length 0) { // Build count of columns that do not have menu disabled var colCount =

  默认的grid是允许用户隐藏列的,下面的代码将此功能禁用了,有时候会用到!

if(g.enableColumnHide !== false){
    if (this.cm.config.length > 0) {
        // Build count of columns that do not have menu disabled
        var colCount = 0;

        for (var i = 0; i < this.cm.config.length; i++) {
            if (this.cm.config[i].menuDisabled == false) colCount++;
        }

        // Build count of columns that are hideable
        var hideCount = 0;

        for (var i = 0; i < this.cm.config.length; i++) {
            if (this.cm.config[i].hideable == false) hideCount++;
        }

        //
        if (hideCount < colCount) {
            this.hmenu.add('-',
                {id:"columns", text: this.columnsText, menu: this.colMenu, iconCls: 'x-cols-icon'}
            );
        }
    }
}

看隐藏前后的图片:

修改前

修改后

下面是override Ext grid的代码:

Ext.override(Ext.grid.GridView,{
 
    renderUI : function(){
 
        var header = this.renderHeaders();
        var body = this.templates.body.apply({rows:''});
 
        var html = this.templates.master.apply({
            body: body,
            header: header
        });
 
        var g = this.grid;
 
        g.getGridEl().dom.innerHTML = html;
 
        this.initElements();
 
        // get mousedowns early
        Ext.fly(this.innerHd).on("click", this.handleHdDown, this);
        this.mainHd.on("mouseover", this.handleHdOver, this);
        this.mainHd.on("mouseout", this.handleHdOut, this);
        this.mainHd.on("mousemove", this.handleHdMove, this);
 
        this.scroller.on('scroll', this.syncScroll,  this);
        if(g.enableColumnResize !== false){
            this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
        }
 
        if(g.enableColumnMove){
            this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
            this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
        }
 
        if(g.enableHdMenu !== false){
            if(g.enableColumnHide !== false){
                this.colMenu = new Ext.menu.Menu({id:g.id + "-hcols-menu"});
                this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
                this.colMenu.on("itemclick", this.handleHdMenuClick, this);
            }
            this.hmenu = new Ext.menu.Menu({id: g.id + "-hctx"});
            this.hmenu.add(
                {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
                {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
            );
            if(g.enableColumnHide !== false){
                if (this.cm.config.length > 0) {
                    // Build count of columns that do not have menu disabled
                    var colCount = 0;
 
                    for (var i = 0; i < this.cm.config.length; i++) {
                        if (this.cm.config[i].menuDisabled == false) colCount++;
                    }
 
                    // Build count of columns that are hideable
                    var hideCount = 0;
 
                    for (var i = 0; i < this.cm.config.length; i++) {
                        if (this.cm.config[i].hideable == false) hideCount++;
                    }
 
                    //
                    if (hideCount < colCount) {
                        this.hmenu.add('-',
                            {id:"columns", text: this.columnsText, menu: this.colMenu, iconCls: 'x-cols-icon'}
                        );
                    }
                }
            }
            this.hmenu.on("itemclick", this.handleHdMenuClick, this);
 
            //g.on("headercontextmenu", this.handleHdCtx, this);
        }
 
        if(g.trackMouseOver){
            this.mainBody.on("mouseover", this.onRowOver, this);
            this.mainBody.on("mouseout", this.onRowOut, this);
        }
        if(g.enableDragDrop || g.enableDrag){
            this.dragZone = new Ext.grid.GridDragZone(g, {
                ddGroup : g.ddGroup || 'GridDD'
            });
        }
 
        this.updateHeaderSortState();
    }
 
});
声明:本站教程文章版权为一起Ext(http://www.17ext.com/)所有,转载请注明出处
顶一下
(11)
100%
踩一下
(0)
0%
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
推荐内容