Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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). My grid is called ‘divInfoConfig’.

I have created a dynamic grid through a JSON.

What would I like to do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

How have I tried?

The function removeSelectedRecords() does the following:

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

This is because I selected 2 records.

The problem:

The button does nothing. It should delete the selected records.

Any idea on what I am doing wrong?

>Solution :

You are using the native JS delete operator. You should be using 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();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading