Reputation: 359
I am using datatable plugin for table when I am trying to delete current row, the first row getting delete from datatable and in search also that deleted row shoudnot display
this is my jQuery code:
var table = $('#stockistTable').DataTable();
index = $(this).closest('tr').index();
table.row(index.rowIndex-1).remove().draw( false );
Upvotes: 4
Views: 11284
Reputation: 359
var dtRow=0; //declare this globally
dtRow = $(this).closest('tr'); //assigning value on click delete
var stockistTable=$('#stockistTable').DataTable();
stockistTable.row(dtRow).remove().draw( false );
This Code worked for me!!!!
Upvotes: 1
Reputation: 1542
This example here demonstrates how to delete rows from a click event - it should do the trick for you.
Upvotes: -1
Reputation: 1856
Following code will be helpful to you,
var table = $('#stockistTable').DataTable();
var index = $(this).closest("tr")[0];
table.fnDeleteRow(table.fnGetPosition(index));
Upvotes: 2
Reputation: 707
You can make a Jquery object of the entire row element and pass it in row()
function of Datatable.
var table = $('#stockistTable').DataTable();
var removingRow = $(this).closest('tr');
table.row(removingRow).remove().draw();
Upvotes: 4
Reputation: 2606
You can try this
$(document).ready(function() {
var table = $('#stockistTable').DataTable();
$('tr').on("click", function(e) {
index = $(this).closest('tr').index();
table.row( $(this) ).remove().draw();
});
} );
Upvotes: 3