I have a piece of code that delete a record and reload dataTable. I want to animate this action as such that on click the button the record of dataTable fade out and then delete from Data Base.
this is my code:
$(document).on('click', '.delete', function() {
var _id = $(this).attr("id");
data._id = $(this).attr("id");
data.operation = "deleteorderdetail";
// alert(data.operation);
if (confirm("Are you sure?")) {
$.ajax({
url: 'delete.php',
method: 'POST',
data,
success: function(data) {
$(this).parentsUntil("tr").hide(1000); -----> not work !
dataTable.ajax.reload();
}
});
} else {
return false;
}
Best regards….
2
Answers
for Datatable try this may help you
try like this
You can make the following changes to your approach:
Use this clicked item when you select the row to be hidden.
Instead of using
parentsUntil
, useclosest
. UsingparentsUntil
will select every ancestor from your clicked object up to but not including the selected element (the<tr>
in your case). I assume that what you want is to hide the entire row.The reason for performing step 1: If you try to use
$(this).closest("tr").hide(1000);
, then$(this)
will refer to the jQuery Ajax object in which$(this)
is located.The end result: