Complete Noob - Deleting multiple selected rows

Complete Noob - Deleting multiple selected rows

jmreslerjmresler Posts: 2Questions: 0Answers: 0
edited September 2013 in DataTables 1.9
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

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    [code]
    $("#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
  • jmreslerjmresler Posts: 2Questions: 0Answers: 0
    Thanks Allan, I really appreciate it. Is the fnDraw method absolutely necessary to be called? It looks like the UI is updating properly without it.
This discussion has been closed.