jQuery Datatables:如何删除行

时间:2022-05-08 11:42:30

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

我想从datatable中删除行。下面是我使用的数据代码:

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:

我想测试一个事件来从datatable中删除一行。事件是由datatables表DOM之外的按钮触发的。我试着这样做:

$('.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 个解决方案

#1


7  

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

在这里找到以下评论: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."

“因为您正在使用服务器端处理,而fnDeleteRow对服务器端环境一无所知,所以需要对服务器进行Ajax调用,让它执行删除,然后调用fnDraw在表上刷新新的数据集。”

#1


7  

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

在这里找到以下评论: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."

“因为您正在使用服务器端处理,而fnDeleteRow对服务器端环境一无所知,所以需要对服务器进行Ajax调用,让它执行删除,然后调用fnDraw在表上刷新新的数据集。”