如何在dojox.grid.DataGrid中启用浏览器上下文菜单?
我试图让浏览器上下文菜单在 dojox.grid.DataGrid 中工作。当我现在右键单击网格时,什么也没有发生。我尝试在网格实例上使用空函数覆盖 onCellContextMenu、onRowContextMenu、doContextMenu 和 oncontextmenu,但这不起作用。右键单击时会调用 onCellContextMenu 方法,但它仍然不显示上下文菜单。我认为该活动在另一个层面上被停止了,但我不知道该去哪里寻找。
网格有一个链接列表,我希望用户能够右键单击链接,以便他们可以在新选项卡中打开它们。我知道我可以制作自定义上下文菜单来提供该功能,但我想知道将来如何禁用此行为。
I'm trying to get the browser context menu to work inside a dojox.grid.DataGrid. When I right-click on the grid now, nothing happens. I tried overriding onCellContextMenu, onRowContextMenu, doContextMenu, and oncontextmenu with empty functions on the grid instance, but that didn't work. The method onCellContextMenu is called on a right-click, but it still doesn't show a context menu. I think the event is being stopped at another level, but I'm not sure where to look.
The grid has a list of links, and I want users to be able to right click on links so they can open them in a new tab. I know that I can make a custom context menu to provide that functionality, but I'd like to know how to disable this behavior in the future.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这并不完全是您想要显示上下文菜单的解决方案,但是您是否尝试过告诉您的用户在这些链接上按 Ctrl-leftClick 而不是右键单击来显示上下文菜单?
I know it's not exactly the solution you want for displaying the context menu, but have you tried telling your users to Ctrl-leftClick on those links rather right-click to display the context menu ?
您需要在 div 中创建一个 dijit.menu 并将其显示设置为 none。下面是一个示例,其中上下文菜单和网格包含在 dijit ContentPane 中:
创建菜单时,您还需要将菜单连接到网格:
You need to create a dijit.menu in a div and set its display to none. Here's an example where the context menu and grid are contained in a dijit ContentPane:
You will also need to connect the menu to your grid when you create it:
我知道这可能有点晚了,但我遇到了同样的问题,并通过研究源代码并在道场社区聊天中询问找到了解决方案。该解决方案涉及创建一个具有以下修改的自定义网格小部件:
创建自定义网格将使用的自定义 _FocusManager,其中唯一的更新是删除默认情况下执行 dojo.stopEvent 的 doContextMenu 方法的功能 -
//删除上下文菜单的扩展 dojo.stopEvent
dojo.declare('myGrid.dojox.grid._FocusManager', dojox.grid._FocusManager, {
doContextMenu: 函数() {}
});
去掉网格中原来默认执行dojo.stopEvent的回调:
//移除原来调用stopEvent的回调
这是我在社区聊天中给出的一个工作示例: http://jsfiddle.net/kfranqueiro/SqYXd/
I know that this may be a bit late, but I ran into the same exact problem and found a resolution by studying the source code and asking around the dojo community chat. The solution involves creating a custom Grid widget that has the following modifications:
Create a custom _FocusManager that your custom grid will use, where the only update is removing the functionality of the doContextMenu method which executes a dojo.stopEvent by default -
//extension to remove contextmenu dojo.stopEvent
dojo.declare('myGrid.dojox.grid._FocusManager', dojox.grid._FocusManager, {
doContextMenu: function() {}
});
Remove the original callbacks in the grid that execute dojo.stopEvent by default:
//remove original callbacks that call stopEvent
Here is a working example that I was given at the community chat: http://jsfiddle.net/kfranqueiro/SqYXd/