Muti-Select Delete of Rows

Muti-Select Delete of Rows

kraftomatickraftomatic Posts: 78Questions: 13Answers: 0
edited March 2012 in DataTables 1.9
Hey Guys,

How can I setup a multi-select/delete rows link/button, pulling from an external data source (arrays.txt for example)? I can do a single-row delete and a standard mult-row select - but I haven't been able to get the delete functionality to work within the dataTable.

Thanks.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi,

    I presume that your information for the table is coming from a database? So what you would need to do is send a POST to the server with the IDs of the rows that you want to delete (you can use DT_RowId to automatically have an ID added to the TR element, which is very useful for this kind of thing).

    Then once the POST is complete and the rows successfully deleted from the database, you would either use fnDeleteRow to delete the currently selected rows, or use fnReloadAjax to reload the table.

    To delete rows that are selected you could do something like this:

    [code]
    table.$('input:checked').each( function () {
    var tr = $(this).parents('tr')[0];
    table.fnDeleteRow( tr, false );
    } );
    table.fnDraw();
    [/code]

    The fnDraw call at the end is just an optimisation along with the second parameter for fnDeleteRow being false so that only one redraw is needed.

    Regards,
    Allan
This discussion has been closed.