当前位置:编程学习 > 网站相关 >>

Ext之grid右键菜单

Ext.ns('Ext.ux.grid'); 
Ext.ux.grid.RightMenu = function(options) { 
    var currRecord = false; 
    var currRowIndex = false; 
    var currGrid = false; 
    var menuItems = Ext.each(options.items, function() { 
                var item = this; 
                this.handler = function() { 
                    item.recHandler 
                            && item.recHandler(currRecord, currRowIndex, 
                                    currGrid); 
                }; 
            }); 
    var menu = new Ext.menu.Menu({ 
                items : options.items 
            }); 
    this.init = function(grid) { 
        grid.addListener('rowcontextmenu', function(client, rowIndex, e) { 
                    e.preventDefault(); 
                    if (rowIndex < 0) { 
                        return; 
                    } 
                    client.getSelectionModel().selectRow(rowIndex); 
                    currRowIndex = rowIndex; 
                    currRecord = grid.getStore().getAt(rowIndex); 
                    currGrid = grid; 
                    menu.showAt(e.getXY()); 
                }); 
    }; 
}; 


[javascript] view plaincopy var rightMenu = new Ext.ux.grid.RightMenu({ 
            items : [{ 
                        text : '增加', 
                        recHandler : onAdd 
                    }, { 
                        text : '删除', 
                        recHandler : function(record, rowIndex, grid) { 
                            alert(1); 
                        } 
                    }] 
        }); 

 

只需要将上面代码作为插件使用就OK了


[javascript]
 selModel : new Ext.grid.RowSelectionModel({ 
            singleSelect : true 
        }), 
plugins : [rightMenu], 

补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,