1、首先禁用浏覽器預設右鍵菜單,代碼如下:
将下列代碼加到Ext.onReady()中即可解決:
Ext.getDoc().on("contextmenu", function(e){
e.stopEvent();
}); 2、我們以Ext.grid.Panel為例,先建立一個右鍵菜單項:
var rightClick= Ext.create('Ext.menu.Menu', {
width: 100,
height: 100,
plain: true,
floating: false, // usually you want this set to True (default)
renderTo: Ext.get('grid'), // usually rendered by it's containing component
items: [{
text: '增加'
},{
text: '删除'
},{
text: '修改'
}]
});
3、接下來添加
//添加右鍵監聽
grid.addListener('containercontextmenu', rightClickFn,this);
4、定位菜機關置:
function rightClickFn(client,e) {//client ;rowIndex:鍵盤,
e.stopEvent();//此方法也可關閉預設右鍵菜單
//e.preventDefault();//預設浏覽器菜單
rightClick.showAt(e.getXY());
};
完善中...