jquery数据表添加未定义的行

jquery datatable add row undefined?

本文关键字:未定义 添加 数据表 jquery      更新时间:2023-09-26

在尝试向jquery DataTable添加一行时,我将执行以下操作:

//add new status row to the DataTable
$('#errorTable').dataTable().fnAddData( [
     id,
     msg,
     tm
]);

我曾经使用table.row.add([...])下面的代码来添加一行,它确实工作了一段时间,但突然间它给了我以下错误:

中第102行第17列出现未处理的异常http://127.0.0.1:45319/js/errors.js?v=3

0x800a138f-JavaScript运行时错误:无法获取的属性"add"未定义或空引用

var table = $('#errorTable').dataTable();
table.row.add([
    id,
    msg,
    tm
]).draw();

事实上,jQuery文档在自己的示例中没有使用table.row.add代码。我的问题是,为什么它不起作用,为什么fnAddData起作用?我错过了什么或做错了什么?

使用DataTable()访问1.10+版本中引入的较新API方法。例如:

var table = $('#errorTable').DataTable();
table.row.add([id, msg, tm]).draw();

您可以继续使用dataTable()的旧API,例如:

$('#errorTable').dataTable().fnAddData([id,msg,tm]);