【问题标题】:Having issue with deleting row (using button in column) in dojogrid在 dojogrid 中删除行(使用列中的按钮)有问题
【发布时间】:2014-09-28 12:19:54
【问题描述】:

我正在使用 dojo EnhancedGrid 显示一些数据并处理“onRowClick”事件以允许用户单击网格中的一行以查看有关该行的更多详细信息,如下所示。

dojo.connect(grid, "onRowClick", grid, dojo.partial(displayDetailsForSelectedElement, type));

现在,我想允许用户通过在网格中的每一行的单独列中提供一个删除按钮来从网格中删除一个项目。下面提供了按钮的代码。

 function buttonFormatterRemove(col, rowIndex){
    var w = new dijit.form.Button({
        label: "Delete",    //label: '<img src="images/del.png" />',
        iconClass: "dijitIconDelete", //"dijitEditorIcon  dijitIconCut",
        showLabel: false,
        onClick: function() {
                console.log(this);
                //if (confirm("Are you sure you want to delete the assertion?")){
                    alert("Do I come here for delete...");

                    //var item = grid.selection.getSelected();
                    //var work_id = grid.store.getValue(item[0], "work_id");
                    var item = this.grid.getItem(rowIndex);
                    var id = item['id'];
                    alert("delete row with id = " + id);

                    //Send POST request to delete
                    require(["dojo/request"], function(request){
                        request.del(contextPath + "/rest/items/" + id)
                            .then(function(text){
                                    console.log("The server returned: ", text);
                                });
                    });      
                //}          
        }//function
    });
    w._destroyOnRemove=true;
    return w;
}

我遇到的问题是,当我单击一行的删除按钮时,虽然它确实出现在 onClick() 中,但 alert("Do I come here for delete...");不会被调用。之后,它首先执行了alert(),它调用displayDetailsForSelectedElement() 来处理'onRowClick'。

我不确定这个问题是否是由于当我单击删除按钮时触发了 2 个事件以及是否有解决此问题的解决方案?任何帮助和建议将不胜感激。

【问题讨论】:

    标签: datagrid dojo delete-row


    【解决方案1】:

    你可以先调用dojo.stopEvent(e)来停止你的delete方法中的事件传播。

    【讨论】:

      猜你喜欢
      • 2020-01-16
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-20
      • 2011-03-03
      • 2017-05-19
      相关资源
      最近更新 更多