I am designing an application which is using a predefined library from DataTables to create the data table. I want to perform remove operation on Datatable, for which java script should get executed on button click event.
$(document).ready(function() {
var table = $('#example').DataTable();
$('#example tbody').on( 'click', 'tr', function () {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
}
else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
});
$('#button').click(function() {
table.row('.selected').remove().draw(false);
});
});
HTML button is:
<button type="button" class="btn btn-primary btn-sm">Remove</button>
Clicking this button should execute above script and the selected row should get deleted from the datatable.