Complete Noob - Deleting multiple selected rows
Complete Noob - Deleting multiple selected rows
jmresler
Posts: 2Questions: 0Answers: 0
Hi,
I have a table with a checkbox in each row. If a single or multiple checkboxes are selected and the delete row button is pushed, the rows should be deleted. I am using the following code:
[code]
$("#deleteRowButton").click(function()
{
var numRows = $("#timesheet tbody tr").length;
var numChecked = $("#timesheet tbody tr td input:checkbox:checked").length;
// iterate through rows, deleting the selected rows...
});
[/code]
The two checks at the start work properly. When I access the row using straight javascript to check if that row has been selected and then use fnDeleteRow, I wind up deleting every row in the table. Sorry, that code was 95 iterations ago. I have tried several methods to process each row with no success. I'm really new to JavaScript/JQuery/Datatables so a little patience would be appreciated it. Any suggestions re: checking the row to delete and proceeding from there?
(Great product BTW!)
Thanks,
JR
I have a table with a checkbox in each row. If a single or multiple checkboxes are selected and the delete row button is pushed, the rows should be deleted. I am using the following code:
[code]
$("#deleteRowButton").click(function()
{
var numRows = $("#timesheet tbody tr").length;
var numChecked = $("#timesheet tbody tr td input:checkbox:checked").length;
// iterate through rows, deleting the selected rows...
});
[/code]
The two checks at the start work properly. When I access the row using straight javascript to check if that row has been selected and then use fnDeleteRow, I wind up deleting every row in the table. Sorry, that code was 95 iterations ago. I have tried several methods to process each row with no success. I'm really new to JavaScript/JQuery/Datatables so a little patience would be appreciated it. Any suggestions re: checking the row to delete and proceeding from there?
(Great product BTW!)
Thanks,
JR
This discussion has been closed.
Replies
$("#timesheet tbody tr td input:checkbox:checked").each( function () {
table.fnDeleteRow( $(this).parents('tr')[0], false );
} );
// Redraw only once (second parameter passed to fnDeleteRows stops it redrawing on each iteration).
table.fnDraw();
[/code]
Allan