我如何为 extjs 网格创建上下文菜单
我可以为树创建上下文菜单并附加到“contextmenu”事件。 代码:
contextMenu = new Ext.menu.Menu({
items: [{
text: 'Edit',
iconCls: 'edit',
handler: edit
},...]
})
Ext.getCmp('tree-panel').on('contextmenu', function(node) {
contextMenu.show(node.ui.getAnchor());
})
但是如何为网格元素创建上下文菜单?
I can create context menu for tree and attach to 'contextmenu' event.
Code:
contextMenu = new Ext.menu.Menu({
items: [{
text: 'Edit',
iconCls: 'edit',
handler: edit
},...]
})
Ext.getCmp('tree-panel').on('contextmenu', function(node) {
contextMenu.show(node.ui.getAnchor());
})
But how I can create context menu for grid elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
首先定义上下文菜单
然后为所需事件创建侦听器。记住停止事件的默认行为非常重要,这样您就可以用自己的行为替换它。如果您不调用 event.stopEvent() 方法来停止事件冒泡,那么无论您做什么,浏览器的默认上下文菜单都会出现。
First define your context menu
Then create a listener for the desired event. It is very important to remember to stop the event's default behaviour so you can replace it with your own. If you don't call the event.stopEvent() method to stop the event bubbling onwards then the brower's default context menu will appear regardless of what you do.
好吧,根据您想要执行的操作,您可以按照与示例相同的方式处理以下 GridPanel 事件:上下文菜单,cellcontextmenu,containercontextmenu,groupcontextmenu,headercontextmenu,rowbodycontextmenu 或 rowcontextmenu。
Well, depending on what you want to do you can handle the following
GridPanel
events in the same manner as your example: contextmenu, cellcontextmenu, containercontextmenu, groupcontextmenu, headercontextmenu, rowbodycontextmenu or rowcontextmenu.对于 extjs4,将其添加到网格中:
使用与上面提供的 Alan 相同的菜单上下文。
For extjs4, add this in your grid:
With the same menu context as Alan provided above.
必须在网格中添加此属性,例如:
have to add this property in your grid for example :
创建视图文件
Create a View file