Dojo:如何在网格的上下文菜单项处理程序中获取行数据?
我正在使用 Dojo 1.4。
给定标记中的 dojox.grid.DataGrid:
<table jsId="grid1" dojoType="dojox.grid.DataGrid"
structure="layout"
delayScroll="true"
columnReordering="true"
selectable="true"
onRowDblClick="onRowDblClick"
onRowContextMenu="onRowContextMenu"
headerMenu="grid1_headerMenu"
>
<div dojoType="dijit.Menu" id="grid1_rowMenu" jsId="grid1_rowMenu" style="display: none;">
<div dojoType="dijit.MenuItem" onClick="gridRowContextMenu_onClick">Edit</div>
</div>
</table>
我还没有找到比这更好的方法来显示网格的上下文菜单:
function onRowContextMenu(e) {
grid1_rowMenu.bindDomNode(e.grid.domNode);
}
它有效,弹出菜单并且已调用函数“gridRowContextMenu_onClick”。
function gridRowContextMenu_onClick(e) {
// how to get a row data???
}
我的问题是在 menuitem 的 onClick 处理程序 (gridRowContextMenu_onClick) 内部如何获取弹出菜单的原始行?
I'm using Dojo 1.4.
Given a dojox.grid.DataGrid in markup:
<table jsId="grid1" dojoType="dojox.grid.DataGrid"
structure="layout"
delayScroll="true"
columnReordering="true"
selectable="true"
onRowDblClick="onRowDblClick"
onRowContextMenu="onRowContextMenu"
headerMenu="grid1_headerMenu"
>
<div dojoType="dijit.Menu" id="grid1_rowMenu" jsId="grid1_rowMenu" style="display: none;">
<div dojoType="dijit.MenuItem" onClick="gridRowContextMenu_onClick">Edit</div>
</div>
</table>
I haven't found a better way to show grid's contex menu that this one:
function onRowContextMenu(e) {
grid1_rowMenu.bindDomNode(e.grid.domNode);
}
It works, menu pops up and function 'gridRowContextMenu_onClick' has being called.
function gridRowContextMenu_onClick(e) {
// how to get a row data???
}
My question is how inside menuitem's onClick handler (gridRowContextMenu_onClick) can I get original row for which menu was poped up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用事件网格对象:
You can use the event grid object:
我有类似的问题。我想创建一个上下文菜单,允许用户从数据网格中删除右键单击的项目,并从数据存储中删除该项目。我认为它应该非常简单,在您和其他一些网站的帮助下,我想出了以下代码。我希望这对将来的人有帮助。
Javascript
HTML
当然
,如果您以编程方式创建
DataGrid
,您只需将onRowContextMenu: onRowContextMenuFunc
添加到你的声明,就像你在上面的问题中所做的那样。最后,要实际获取有关该项目的信息:
I had a similar question. I wanted to create a context menu which allowed the user to remove the item that they right clicked on from the datagrid and delete the item from the datastore. Thought it should be pretty simple and with your help and some other sites, I came up with the following code. I hope this helps someone in the future.
Javascript
HTML
and
Of course, if you were programatically creating your
DataGrid
, you would just addonRowContextMenu: onRowContextMenuFunc
to your declaration, as you did in your question above.Finally, to actually get information about the item:
您尝试过 e.rowIndex 吗?
Did you try e.rowIndex?