函数row.add()在我的函数中不起作用:

时间:2019-05-28 19:27:11

标签: javascript jquery datatables

功能row.add无法正常工作,以创建数据表:

var target=$(table.dt-table); //i test and only exist one.
target.DataTable(options);

尝试在同一函数中添加一行:

if(addrow!=null){target.row.add(addrow).draw();} //addrow i a var with array.

我收到此错误:

Uncaught TypeError: Cannot read property 'add' of undefined

我需要在现有数据表中添加一行。以任何方式与row.add()或添加html原始代码。

1 个答案:

答案 0 :(得分:1)

来自api documentation上的row.add()

var table = $('#example').DataTable(); // <-- use the returned object from .DataTable() and not the jQuery object

table.row.add( {
        "name":       "Tiger Nixon",
        "position":   "System Architect",
        "salary":     "$3,120",
        "start_date": "2011/04/25",
        "office":     "Edinburgh",
        "extn":       "5421"
    } ).draw();