刷新jquery数据表

时间:2012-05-17 14:04:33

标签: javascript jquery jquery-datatables

我有两个表格,其中包含ID Tab1和Tab2。

我通过代码做什么:

在按钮的onclick事件中删除一行Tab2并将其添加到Tab1.Initially Tab1不包含数据,这就是为什么在Tab1表中我们使用以下代码显示消息“No Data Available”:

            this.oLanguage = {
            "sProcessing": "Processing...",
            "sLengthMenu": "Show _MENU_ entries",
            "sZeroRecords": "No matching records found",
            "sEmptyTable": "No Data Available",
            "sLoadingRecords": "Loading...",
            "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
            "sInfoEmpty": "Showing 0 to 0 of 0 entries",
            "sInfoFiltered": "(filtered from _MAX_ total entries)",
            "sInfoPostFix": "",
            "sInfoThousands": ",",
            "sSearch": "Search:",
            "sUrl": "",
            "oPaginate": {
                "sFirst":    "First",
                "sPrevious": "Previous",
                "sNext":     "Next",
                "sLast":     "Last"
            },
            "fnInfoCallback": null
        };

但是当Tab1中添加了一行时,它很好但它仍然显示消息“没有数据可用”。这意味着表格不会刷新。

我在javascript中有以下代码:

var oTable1=null;
    var oTable2=null;
    $(document).ready(function() {
    oTable1 =$('#tab1').dataTable( {
    "bPaginate": false,
    "bInfo": false,
    "aSort": false
    }); 

     oTable2 =$('#tab').dataTable( {
    "bPaginate": false,
    "bInfo": false
} );


    });

我该怎么做才能刷新表格,以便在添加数据后不应显示“无可用数据”消息?

1 个答案:

答案 0 :(得分:1)

使用oTable.fnAddData方法添加新行。

使用oTable.fnDraw方法调用重绘方法。

相关问题