gpt4 book ai didi

Dojo DataGrid 上下文菜单 onRowContextMenu 即使在 DataGrid 的空白区域中右键单击时也会显示

转载 作者:行者123 更新时间:2023-12-04 06:07:26 33 4
gpt4 key购买 nike

我有一个包含项目的 DataGrid。当您右键单击其中一行时,会显示一个 Dojo 上下文菜单,其中包含删除该行的选项。如果您尝试右键单击 DataGrid 的空白区域,则不会显示上下文菜单……但是,如果您首先右键单击一行,然后单击“取消”菜单选项(什么都不做),或者如果您左键单击页面上的其他位置(隐藏上下文菜单),然后右键单击 DataGrid 的空白区域,显示上下文菜单,如果您单击上下文菜单中的删除项目选项,它会删除您右键单击的最后一个项目。

为什么在 中右键单击时允许显示上下文菜单空白区域的 DataGrid 但只有在您已经右键单击 DataGrid 中的项目之后?

任何提示将不胜感激。到目前为止,这是我的代码:

var selectedItem;  // This has to be declared "globally" outside of any functions

function onRowContextMenuFunc(e) {
grid5_rowMenu.bindDomNode(e.grid.domNode);
selectedItem = e.grid.getItem(e.rowIndex);
}

function gridRowContextMenu_onClick(e) {
store3.deleteItem(selectedItem);
}

.
<div dojoType="dijit.Menu" id="grid5_rowMenu" jsId="grid5_rowMenu" style="display: none;">
<div dojoType="dijit.MenuItem" onClick="gridRowContextMenu_onClick">Delete</div>
<div dojoType="dijit.MenuItem">Cancel</div>
</div>

.
<div id="grid" dojoType="dojox.grid.DataGrid" jsId="grid5" store="store3" structure="layoutStructure" rowsPerPage="40" onRowContextMenu="onRowContextMenuFunc"></div>

最佳答案

好吧,我不太确定为什么只有在第一次右键单击某个项目后才允许在空白区域中右键单击时才显示上下文菜单,但我确实想出了解决我的根本问题的方法:右键单击数据网格中的行项,然后单击关闭以隐藏上下文菜单,然后右键单击数据网格的空白区域并选择菜单项会导致传递第一次右键单击的 rowIndex

这是我的代码;我希望这可以帮助将来遇到相同问题的任何人:

 var selectedItem;

function onRowContextMenu(e) {
grid5_rowMenu.bindDomNode(e.grid.domNode);
selectedItem = e.grid.getItem(e.rowIndex);
}

function gridRowContextMenuExecute(task) {
if((task == "remove") && (selectedItem != null)) {
store3.deleteItem(selectedItem);
}
else {
selectedItem = null;
}
}

.
 <div dojoType="dijit.Menu" id="grid5_rowMenu" jsId="grid5_rowMenu" style="display: none;" onBlur="gridRowContextMenuExecute('cancel')">
<div dojoType="dijit.MenuItem" onMouseDown="gridRowContextMenuExecute('remove')">Remove from Transaction</div>
<div dojoType="dijit.MenuItem">Cancel</div>
</div>

.
 <div id="grid" dojoType="dojox.grid.DataGrid" jsId="grid5" store="store3" structure="layoutStructure" rowsPerPage="40" onRowContextMenu="onRowContextMenu"></div>

关于Dojo DataGrid 上下文菜单 onRowContextMenu 即使在 DataGrid 的空白区域中右键单击时也会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8187693/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com