Extjs给控件添加右键菜单

//以 grid 为例

Ext.onReady(function(){

         Vargrid = new Ext.grid.GridPanel({

                   Title:’表格实例’,

renderTo:Ext.getBody(),

//定义导入数据源到表格

                   Store:store,

Width:400,

Height:400,

Columns:[{

         Header:’姓名’,

dataIndex:’name’,

sortable:treu

},{

         Header:’年龄’,

         dataIndex:’age,

         sortable:treu

},{

         Header:’性别’,

dataIndex:’sex,

sortable:treu

}]

})



//创建右键菜单选项键

Var rightMenu = new Ext.menu.Menu({

         Id:’rightclickCount’,

         Items:[

{

Id:’rMenu1’,

Text:”添加新学生”,

Handler:function(){

         Alert(“右键菜单一”);

//事件函数调用

}

        

},{

Id:’rMenu2’,

Text:’学社信息’,

Handler:function(){

         Alert(“右键菜单二”);

                   //事件函数调用

}’

},{

Id:’rMenu3’,

Text:’删除’,

Handler:function(){

         Alert(“右键菜单三”);

                   //事件函数调用

}’

}

]



})

//右键触发事件

Function RightClickMenuFn(){

e.preventDefault();  
         //定位。显示 右键菜单
      rightMenu.showAt(e.getXY());

}




// 给控件添加右键菜单触发事件(rowcontextmenu)
grid.addListener('rowcontextmenu', RightClickMenuFn);



})



Extjs  grid 加入右键菜单。

receiveListGrid.on("rowcontextmenu",function(grid,rowIndex,e){ 
        e.preventDefault(); 
        if(rowIndex<0){return;} 
        var treeMenu = new Ext.menu.Menu 
        ([ 
            { 
                xtype:"", 
                text:"详细", 
                icon:"resources/images/default/dd/drop-yes.gif", 
                pressed:false, 
                handler:function(){ 
                    //获得行数据  
                    var record = grid.getStore().getAt(rowIndex); 
                    open_receive_detailWindow(record.data.smsIndex); 
                    //record.data.taskId  
                } 
            },{ 
                xtype:"", 
                text:"删除", 
                icon:"resources/images/default/dd/drop-yes.gif", 
                pressed:false, 
                handler:function(){ 
                    //获得行数据  
                    var record = grid.getStore().getAt(rowIndex); 
                    delReceivedMessage(record.data.smsIndex); 
                } 
            } 
        ]); 
        treeMenu.showAt(e.getXY()); 
       });  

你可能感兴趣的:(ExtJs)