2010-04-17 21 views
1

我正在寻找一个dojo增强网格的示例,该网格包含单元格或行菜单中单元或行数据访问的上下文菜单。我设法使用行上下文菜单创建增强型网格。我可以创建一个捕获点击行菜单项的事件的函数。但是,我不确定如何在菜单项处理程序的上下文中访问行数据。我在夜间搭建的测试中没有看到任何例子。有没有这种在线可用的例子?是否有带上下文菜单的dojo增强网格示例

+0

你能解释一下如何捕捉事件中的行号吗?因为我没有看到如何去做。谢谢。 – 2011-01-18 18:49:19

回答

0

我想通了。甚至在行上下文菜单上,将行号捕获到全局中。即使在菜单项上单击,也可以从全局中检索行,然后使用它查找网格中行的内容。我一直在使用这种方法,它的工作非常完美。

1

我有一个类似的问题。我想创建一个上下文菜单,允许用户从数据网格中删除他们右键单击的项目,并从数据存储中删除项目。认为它应该是非常简单的,并与您的帮助和其他网站,我想出了以下代码。

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> 

当然,如果你是编程创建的DataGrid,你想补充onRowContextMenu:onRowContextMenuFunc你的声明。

+0

编辑:有上述代码的一些问题,它允许用户右键单击一行,然后单击取消或以其他方式隐藏上下文菜单,然后右键单击数据网格的空白区域,然后单击删除菜单选项它会删除先前右键单击的项目。如果你有同样的问题,请查看我修改的代码[这里](http://stackoverflow.com/questions/8187693/dojo-datagrid-context-menu-onrowcontextmenu-displays-even-when-right-clicking-在/ 8216093#8216093) – 2011-11-21 19:00:35

0

以下是如何从上下文菜单中访问选定行:

// First create a menu object to hold the various menus 
var menusObject = { 
    // headerMenu: new dijit.Menu(), 
rowMenu: new dijit.Menu()//, 
// cellMenu: new dijit.Menu(), 
// selectedRegionMenu: new dijit.Menu() 
}; 

添加菜单项

menusObject.rowMenu.addChild(new dijit.MenuItem({ 
    label: "Show me data", 
    onClick: function(e){ 
     console.log(this.selectedRow) 
    } 
})); 

menusObject.rowMenu.startup(); 

创建网格

var grid = new dojox.grid.EnhancedGrid({ 
    store : store, 
structure : layout, 
rowsPerPage: 10, 
escapeHTMLInData: false, 
plugins: { 
    menus: menusObject 
} 
}, 'some are to place'); 

//激活消息从发送数据网格排到菜单项

dojo.connect(grid, 'onRowContextMenu', function(e) 
{ 
    // Set the "selectedItem" property of all of the menu items of a menu. This lets you reference the row data!! 

    var menuChildren = menusObject.rowMenu.getChildren(); 
    for(var i = 0; i<menuChildren.length; i++){ 
     menuChildren[i].selectedRow = this.getItem(e.rowIndex); 
    } 
});