Originally, I have a datatable which can be viewed at the following link:
The functionality I am experiencing is related to a "DISABLE" button that toggles to "ENABLE" and vice versa upon clicking. However, if you click on the same button after it has already changed, no action is triggered.
// Code for delete function
$('#saiMdataEnvListTable .delete').on('click', function() {
var ans = confirm("Do you want to delete this Environment?");
if(ans==true){
var nRow = $(this).parents('tr')[0];
var target_row = $(this).closest("tr").get(0); // this line did the trick
var aPos = oTable.fnGetPosition(target_row);
oTable.fnUpdate('T',aPos,1);
oTable.fnUpdate('<td class="center"><a href="JavaScript:void()" class="button enable" style="margin:10px;margin-right:30px;">Enable</a></td> ',aPos,6);
$.ajax({
url: "deleteEnv.do",
data: "env=" + nRow.id + "&flag=" + "T",
success: function(response) {
oTable.fnDraw(false)
toastr.success(response.message);
}
})
}
});
// Code for enable function
$('#saiMdataEnvListTable .enable').on('click', function() {
var ans = confirm("Do you want to enable this Environment?");
if(ans==true){
var nRow = $(this).parents('tr')[0];
var target_row = $(this).closest("tr").get(0);
var aPos = oTable.fnGetPosition(target_row);
oTable.fnUpdate('F',aPos,1);
oTable.fnUpdate('<td class="center"><a href="JavaScript:void()" class="button delete" style="margin:10px;margin-right:30px;">Disable</a></td> ',aPos,6);
$.ajax({
url: "enableEnv.do",
data: "env=" + nRow.id + "&flagt=" + "F",
success: function(response) {
oTable.fnDraw(false)
toastr.success(response.message);
}
})
}
});
Your assistance will be highly valuable. Thank you in advance.