jQuery Datatables: how to delete the row

拥有回忆 提交于 2019-12-07 04:09:51

问题


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?


回答1:


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."



来源:https://stackoverflow.com/questions/10214307/jquery-datatables-how-to-delete-the-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!