For some reason it only removes the first row and not sure why.
function templatesArray(whatsThis) {
var myNewArray = new Array();
var aRow = new Array();
$('input:checkbox[name="templates"]:checked').each(function(i) {
myNewArray.push($(this).val());
aRow.push(oTable.fnGetPosition( $(this).parents('tr').get(0)));
});
var dataString = 'templatesArray=' + myNewArray + '&deleteTemplatesArray=True';
$.ajax({
type: "POST",
url: "processes/templates.php",
data: dataString,
success: function(data) {
if (data.errorsExist) {
} else {
$(whatsThis).parents("tr").eq(0).hide();
for (i in aRow) // loop over the array of row indexes
oTable.fnDeleteRow(aRow[i]);
if(oTable.fnSettings().fnRecordsTotal() == 0) {
$('.bt_red').remove();
$('.bt_blue').remove();
}
if(oTable.fnSettings().fnRecordsTotal() <= 10) {
$('.bt_blue').remove();
}
if(oTable.fnSettings().fnRecordsTotal() <= 10) {
$('div.pagination').remove();
}
}
}
});
}
Avoid using
for .. inon Arrays. You can get unexpected results. Instead useArray.foreachor jQuery’s$.each():If that doesn’t fix it, please post more details, such as the code for
oTable.fnDeleteRow(). Are any JavaScript errors being thrown?Edit: Your code is passing the row index to the delete function. After the delete function is called all proceeding rows have a new row index. So if you try to delete rows 1, 2, and 3, you’ll end up deleting rows 1, 3, and 5. Instead store and pass a reference to the row itself:
http://jsfiddle.net/3Ldj5/2/