Dojo DataGrid上下文菜单onRowContextMenu显示即使右键单击DataGrid的空白区域 [英] Dojo DataGrid Context Menu onRowContextMenu displays even when right-clicking in BLANK area of DataGrid
问题描述
为什么在右键单击DataGrid的空白区域时可以显示上下文菜单但是只有您之前已经右键单击DataGrid中的某个项目?
任何提示都将不胜感激。这是我的代码到目前为止:
var selectedItem; //这必须在任何函数之外被声明为全局
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.Menuid =grid5_rowMenujsId =grid5_rowMenustyle =display:none;>
< div dojoType =dijit.MenuItemonClick =gridRowContextMenu_onClick> Delete< / div>
< div dojoType =dijit.MenuItem>取消< / div>
< / div>
。
< div id =griddojoType =dojox.grid.DataGridjsId =grid5store =store3structure =layoutStructurerowsPerPage =40onRowContextMenu =onRowContextMenuFunc>< / DIV>
嗯,我不知道为什么允许右键单击一个项目后,右键单击空白区域的上下文菜单,但我确实想到了解决根本问题的工作: 右键单击一个行项目数据网格,然后点击关闭隐藏上下文菜单,然后右键单击数据网格的空白区域,并选择一个菜单项导致第一个右键单击的rowIndex被传递
这是我的代码;我希望这有助于将来遇到同样问题的任何人:
var selectedItem;
函数onRowContextMenu(e){
grid5_rowMenu.bindDomNode(e.grid.domNode);
selectedItem = e.grid.getItem(e.rowIndex);
}
函数gridRowContextMenuExecute(task){
if((task ==remove)&&(selectedItem!= null)){
store3 .deleteItem(将selectedItem);
}
else {
selectedItem = null;
}
}
。
< div dojoType =dijit.Menuid =grid5_rowMenujsId =grid5_rowMenustyle =display:none;的onblur =gridRowContextMenuExecute(取消)>
< div dojoType =dijit.MenuItemonMouseDown =gridRowContextMenuExecute('remove')>从事务中删除< / div>
< div dojoType =dijit.MenuItem>取消< / div>
< / div>
。
< div id =griddojoType =dojox.grid.DataGridjsId =grid5store =store3structure =layoutStructurerowsPerPage =40onRowContextMenu =onRowContextMenu>< / DIV>
I have a DataGrid that has items in it. When you right-click on one of the rows, a Dojo Context Menu is displayed with the option to delete that row. If you try to right-click on a blank area of the DataGrid, the context menu is NOT displayed.... BUT, if you first right click on a row, and then click the Cancel menu option (which does nothing) or if you left-click somewhere else on the page (which hides the Context Menu) and the go to right click on a blank area of the DataGrid, the Context Menu IS displayed and if you click the Delete Item option in the Context Menu, it removes the last item you right clicked on.
Why is it allowing the context menu to show when you right click in a blank area of the DataGrid but only AFTER you've already right clicked on a item in the DataGrid?
Any tips would be appreciated. Here is my code so far:
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>
Well, I'm not exactly sure why it's allowing the context menu to show when right clicking in a blank area only after first right clicking on an item, but I did come up with a work around to fix my root problem: Right clicking on a row item in a data grid, then clicking off to hide the context menu, then right clicking in a blank area of the data grid and selecting a menu item causes the rowIndex of the first right click to be passed
Here is my code; I hope this helps anyone in the future which has the same problem:
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的空白区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!