如何在dojox.grid.DataGrid中启用浏览器上下文菜单?

发布于 2024-08-19 20:01:30 字数 315 浏览 6 评论 0原文

我试图让浏览器上下文菜单在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

栩栩如生 2024-08-26 20:01:31

我知道这并不完全是您想要显示上下文菜单的解决方案,但是您是否尝试过告诉您的用户在这些链接上按 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 ?

愚人国度 2024-08-26 20:01:31

您需要在 div 中创建一个 dijit.menu 并将其显示设置为 none。下面是一个示例,其中上下文菜单和网格包含在 dijit ContentPane 中:

<div dojoType="dijit.layout.ContentPane" title="MyGrid">
    <div id="myGridContainer" style="width:100%;height:100%"></div>
    <div id="myGridContextMenu" dojoType="dijit.Menu" style="display: none;">
        <div dojoType="dijit.MenuItem" id="myGridContextMenu.delete" onClick="deleteItem">Delete</div>
    </div>
</div>

创建菜单时,您还需要将菜单连接到网格:

var myGrid = new dojox.grid.DataGrid({ ..., onRowContextMenu: myGridcontextMenu },...);

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:

<div dojoType="dijit.layout.ContentPane" title="MyGrid">
    <div id="myGridContainer" style="width:100%;height:100%"></div>
    <div id="myGridContextMenu" dojoType="dijit.Menu" style="display: none;">
        <div dojoType="dijit.MenuItem" id="myGridContextMenu.delete" onClick="deleteItem">Delete</div>
    </div>
</div>

You will also need to connect the menu to your grid when you create it:

var myGrid = new dojox.grid.DataGrid({ ..., onRowContextMenu: myGridcontextMenu },...);
梦里梦着梦中梦 2024-08-26 20:01:30

我知道这可能有点晚了,但我遇到了同样的问题,并通过研究源代码并在道场社区聊天中询问找到了解决方案。该解决方案涉及创建一个具有以下修改的自定义网格小部件:

  1. 创建自定义网格将使用的自定义 _FocusManager,其中唯一的更新是删除默认情况下执行 dojo.stopEvent 的 doContextMenu 方法的功能 -
    //删除上下文菜单的扩展 dojo.stopEvent
    dojo.declare('myGrid.dojox.grid._FocusManager', dojox.grid._FocusManager, {
    doContextMenu: 函数() {}
    });

  2. 去掉网格中原来默认执行dojo.stopEvent的回调:

    //移除原来调用stopEvent的回调

    onRowContextMenu: 函数(e) {},
    onHeaderContextMenu: 函数(e) {}
    

这是我在社区聊天中给出的一个工作示例: 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:

  1. 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() {}
    });

  2. Remove the original callbacks in the grid that execute dojo.stopEvent by default:

    //remove original callbacks that call stopEvent

    onRowContextMenu: function(e) {},
    onHeaderContextMenu: function(e) {}
    

Here is a working example that I was given at the community chat: http://jsfiddle.net/kfranqueiro/SqYXd/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文