I want to remove some rows from datatable based on their respective indexes.The indexes are in form of an array. Upon clicking a button the function gets the array and finds each of them in the datatable then remove them .I have been able to create the code and its able to execute perfectly.Now the issue is not all the rows are removed,lets say we have 5 rows that we want to remove only 2 rows are removed.How can i remove all the rows in the table with all the respective indexes.This is my code
var productsIds=['2','3','4','5','6']
var productsTable=$('#productsTable').DataTable()
productsIds.forEach(function(id) {
var columnIndex = 0;
var rowIndex = productsTable.column(columnIndex).data().indexOf(id);
productsTable.row(rowIndex).remove();
});
productsTable.draw();
row.remove
method says, "Please be aware that this method removes the data from the table internally but that action won't be visually shown until the draw() method is called to update the display. " - now that doesn't exactly clarify what "internally" means, but my guess here would be, thatproductsTable.column(columnIndex).data()
still operates on the original data set, even after rows were removed - so that the index you determine based on that, will simply be "off". [...]