//绑定右键弹出事件
Ext.getCmp("StuList").on("rowcontextmenu", open_rowcontextmenu); //StuList指的是GridPanel的Id
//右键菜单事件
function open_rowcontextmenu(grid, rowIndex, e) {
e.preventDefault();
grid.getSelectionModel().selectRow(rowIndex); //右键选中某行
// 定义右键菜单
var menus = new Ext.menu.Menu
([
{
xtype: "", text: "智育成绩", icon: '../images/button/add.gif',
menu: new Ext.menu.Menu([
{ xtype: "", text: '录入成绩', icon: '../images/button/add.gif', handler: function () { Edit(grid, rowIndex, e, "录入成绩A"); } },
{ xtype: "", text: '编辑成绩', icon: '../images/button/edit.gif', handler: function () { Edit(grid, rowIndex, e, "编辑成绩A"); } }
])
},
{
xtype: "", text: "德育成绩", icon: '../images/button/add.gif',
menu: new Ext.menu.Menu([
{ xtype: "", text: '录入成绩', icon: '../images/button/add.gif', handler: function () { Edit(grid, rowIndex, e, "录入成绩B"); } },
{ xtype: "", text: '编辑成绩', icon: '../images/button/edit.gif', handler: function () { Edit(grid, rowIndex, e, "编辑成绩B"); } }
])
},
{
xtype: "", text: "删除成绩", icon: '../images/button/del.gif',
handler: function () { Edit(grid, rowIndex, e, "删除成绩"); }
}
]);
menus.showAt(e.getPoint());
}
function Edit(grid, rowIndex, e, titleInfo) {
if (titleInfo == "录入成绩A") {
//添加代码
}
if (titleInfo == "编辑成绩A") {
//添加代码
}
if (titleInfo == "录入成绩B") {
//添加代码
}
if (titleInfo == "编辑成绩B") {
//添加代码
}
}
实现效果