Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3800

How can I Remove additional rows during editor delete process?

$
0
0

I want to use the preRemove callback to remove one or more additional rows which are linked to the rows being removed using the datatable editor. If I remove the additional rows in the preRemove (or the ajax.success callback), the datatable or editor state is negatively impacted in some way, causing the datatable to remove a row that it isn't supposed to remove and leave one of the rows that it should have deleted.

var removeRowById = function (datatable, id) {
    console.log('deleting #' + id);
    datatable.row('#' + id).remove();
};

editor.on('preRemove', function (e, response) {
    $.each(response.data, function (index, crfkey) {
        console.log('deleted #' + crfkey);
        var rowData = datatable.row('#' + crfkey).data();
        if (rowData.labelkey === 2) {
            removeRowById(datatable, rowData.changed_fields.crfkey.original);
        }
    });
    datatable.draw();
});
}

consider a datatable with the following rows:
row1-old
row1-new
row2-old
row2-new
row3

  1. select row1-new and row2-new
  2. click delete
  3. confirm delete in the editor modal
  4. editor makes ajax call to server to delete the rows in the db
  5. editor calls preRemove
  6. I .remove() the row1-old and the row2-old rows then call datatable.draw()

result:
row1-new

Any thought on how to fix this? I was able to get it working with a single delete by using setTimeout() and delaying the remove by a second, but this doesn't work for multiple rows. This appears to be a re-indexing issue.


Viewing all articles
Browse latest Browse all 3800

Trending Articles