是否有带有上下文菜单的 dojo 增强网格示例

发布于 2024-08-29 06:13:11 字数 160 浏览 5 评论 0原文

我正在寻找一个 dojo 增强网格的示例,其中包含访问单元格或行数据的单元格或行菜单上的上下文菜单。我成功地创建了一个带有行上下文菜单的增强网格。我可以创建一个函数来捕获单击行菜单项的事件。但是,我不确定如何在菜单项处理程序的上下文中访问行数据。我在夜间构建的测试中没有看到任何示例。网上有这方面的例子吗?

I am looking for an example of a dojo enhanced grid that contains a context menu on either a cell or row menu where the cell or row data is accessed. I have managed to create an enhanced grid with a row context menu. I can create a function that captures the event of clicking on the row menu item. However, I am not sure how to access the row data in the context of the menu item handler. I have not seen any example in the tests of the nightly build. Is there an example of this available online?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

如日中天 2024-09-05 06:13:11

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

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 添加到您的声明中。

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.

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>

Of course, if you were programatically creating your DataGrid, you would just add onRowContextMenu: onRowContextMenuFunc to your declaration.

鸠书 2024-09-05 06:13:11

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

I figured it out. On the row context menu even, capture the row number into a global. On a click even on the menu item, retrieve the row from the global and then use it to lookup the contents of the row in the grid. I have been using this method and it has worked perfect.

千鲤 2024-09-05 06:13:11

以下是从上下文菜单访问所选行的方法:

// 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);
    }
});

Here's how to access the selected row from the context menu:

// 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()
};

Add a menu item

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

menusObject.rowMenu.startup();

Create the grid

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

// Activate message sending from data grid row to menu items

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