简体   繁体   English

通过自定义上下文菜单Ag-Grid更新和删除

[英]Update & Delete by Custom Context Menu Ag-Grid

I am using ag-grid with angular 2. 我正在使用角度2的ag-grid。

I have created a custom context menu that has delete and update buttons. 我创建了一个具有删除和更新按钮的自定义上下文菜单。 In a scenario, the user select one or more rows and then right clicks and clicks delete or update button. 在方案中,用户选择一个或多个行,然后单击鼠标右键,然后单击“删除或更新”按钮。

These buttons call some functions those handles with gridOptions in order to get selected rows. 这些按钮使用gridOptions调用那些句柄中的某些函数,以获取选定的行。

However; 然而; when I click the delete or update buttons, I have an error that says this.gripOptions is undefined. 当我单击删除或更新按钮时,出现错误消息this.gripOptions未定义。

Is there any example or documentation about this? 是否有任何有关此的示例或文档? How can I overcome this problem? 我该如何克服这个问题?

Thanks for the replies 感谢您的答复

    var gridOptions = {
        columnDefs: columnDefs,
        enableRangeSelection: true,
        getContextMenuItems: getContextMenuItems,
        allowContextMenuWithControlKey: true
    };
    getContextMenuItems(params) {
        var result = [
            { // custom item
                name: 'Delete',
                action: function () { this.delete()); }
            } 

    return result;
    }

    delete() {
        var selectedRows = this.gridOptions.api.getSelectedRows();
    }

This is because you declared gridOptions as a variable, not as a part of this. 这是因为您将gridOptions声明为变量,而不是其中的一部分。 What you can do is: 您可以做的是:

var vm = this;
vm.gridOptions={...}

[...] [...]

 delete() {
    var selectedRows = vm.gridOptions.api.getSelectedRows();
}

In this way you don't relate on "this", that is difficult to manage in Javascript, but you have a certain reference to the local context 这样,您就不必使用Java很难管理的“ this”,但是您对本地上下文有一定的引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM