jQuery Datatables:如何删除行 [英] jQuery Datatables: how to delete the row

查看:559
本文介绍了jQuery Datatables:如何删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据表中删除该行.这是我使用的数据表代码:

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;
    }
});

我想测试触发事件以从数据表中删除一行.该事件由数据表表DOM外部的按钮触发.我尝试这样做:

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?

推荐答案

在此处找到以下注释:

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

"由于您正在使用服务器端处理,并且fnDeleteRow对服务器端环境一无所知,因此需要对服务器进行Ajax调用以执行删除操作,然后在表上调用fnDraw进行操作用新的数据集刷新."

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

这篇关于jQuery Datatables:如何删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆