简体   繁体   English

如何删除 w2grid (W2UI) 中的选定记录

[英]How to remove selected records in a w2grid (W2UI)

I want to delete selected records in a grid of the W2UI library, for which I am using w2grid ( https://w2ui.com/web/docs/2.0/grid ).我想删除 W2UI 库网格中的选定记录,为此我正在使用 w2grid ( https://w2ui.com/web/docs/2.0/grid )。 My grid is called 'divInfoConfig' .我的网格称为 'divInfoConfig'

I have created a dynamic grid through a JSON.我通过 JSON 创建了一个动态网格。

What would I like to do?我想做什么?

I have a button with the removeSelectedRecords() function, which should behave that if I manually select 1 or more than 1 record, hitting the button should remove them.我有一个带有 removeSelectedRecords() function 的按钮,如果我手动 select 1 或多于 1 条记录,点击该按钮应该会删除它们。

How have I tried?我是如何尝试的?

The function removeSelectedRecords() does the following: function removeSelectedRecords() 执行以下操作:

function removeSelectedRecords() {
    var sel = w2ui['divInfoConfig'].getSelection();
    console.log('Selection: ' + sel);
    if (sel) {
        delete sel;
    }
    w2ui['divInfoConfig'].refresh();
}

The button is as follows:按钮如下:

<button class="w2ui-btn" onclick="removeSelectedRecords();">Remove Selected Records</button>

This is what the console log returns这是控制台日志返回的内容

Selection: 6,7选择:6,7

This is because I selected 2 records.这是因为我选择了 2 条记录。

The problem:问题:

The button does nothing.按钮什么也不做。 It should delete the selected records.它应该删除选定的记录。

Any idea on what I am doing wrong?知道我做错了什么吗?

You are using the native JS delete operator .您正在使用本机 JS 删除运算符 You should be using w2ui delete() .您应该使用w2ui delete()

So in your case it's:所以在你的情况下是:

function removeSelectedRecords() {
    var sel = w2ui['divInfoConfig'].getSelection();
    console.log('Selection: ' + sel);
    if (sel) {
        w2ui.grid.delete(sel);
    }
    w2ui['divInfoConfig'].refresh();
}

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

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