jquery – Remover Row DataTable por ID

Question:

Is it possible to remove a row from the datatable by id? I have a confirmation modal asking if the user wants to delete. If you click yes, it calls a delete function.

$('#confirm-delete').on('show.bs.modal', function(e) {
    var data = $(e.relatedTarget).data();
    $('.btn-ok', this).data('recordId', data.recordId);
    $('#message_confirm_delete').html(data.message);
});
$('#confirm-delete').on('click', '.btn-ok', function(e) {
    var id = $(this).data('recordId');
    $('#confirm-delete').modal('hide');
    $.deleta2(id);
});
$.deleta2 = function (id) {
    var data_table = $('#dataTables-example').DataTable();
    console.log(data_table);
};

Answer:

This resolved…

var data_table = $('#dataTables-example').DataTable();
data_table.row($('#item_'+id)).remove().draw();
Scroll to Top