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