Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Datatables: how to delete the row

I want to delete the row from datatable. Here is the datatables code I use:

var aSelected = [];

oTable = $('.itemPublished').dataTable({
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "bServerSide": true,
    "bProcessing": true,
    "sAjaxSource": "/item/datatable",
    "bDeferRender": true,
    "iDisplayLength":20,
    "aLengthMenu": [[10, 20, 50, 75, 100, 150], [10, 20, 50, 75, 100, 150]],
    "aoColumnDefs": [
            { "bSortable": false, "aTargets": [ 2, 3, 4 ] },
            { "sClass": "left", "aTargets": [ 1 ] }
    ],
    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
        if ( jQuery.inArray(aData.DT_RowId, aSelected) !== -1 ) {
            $(nRow).addClass('row_selected');
        }
        $(nRow).addClass('gradeA');
        return nRow;
    }
});

I wanted to test fire an event to delete a row from the datatable. The event is triggered by a button which is outside of datatables table DOM. I tried doing this:

$('.test').live('click', function () {
    oTable.fnDeleteRow( 0 ); 
});

To check if it can delete the first row from the table, but it does not and nor does it produce any error. Where am I going wrong?

like image 873
Ibrahim Azhar Armar Avatar asked Apr 18 '12 17:04

Ibrahim Azhar Armar


1 Answers

Found the following comment here: http://datatables.net/forums/discussion/6208/hyperlink-event-to-delete-row/p1:

"Since you are using server-side processing, and fnDeleteRow knows nothing about your server-side environment, you need to make an Ajax call to the server for it to do the delete and then call fnDraw on the table for it to refresh with the new data set."

like image 97
Stefan Avatar answered Nov 15 '22 06:11

Stefan