且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在数据表中添加多行jquery

更新时间:2023-12-01 18:29:52

我在这个 FIDDLE

如果你想使用行中的对象添加你应该在datatable init中添加列:

If you want to use objects in rows add you should add columns in your datatable init:

JS

var table3 = $('#exampleTable').DataTable({
    data:[{ "Year": "2012", "Month": "January", "Savings": "$100" },
      { "Year": "2012", "Month": "February", "Savings": "$80" }],
    columns:[{data: 'Year'},
        {data: "Month"},
        {data: "Savings"}]
}); 

但如果不想这样做,可以使用行中的下一个语法add:

but if you don't want to do this you can use next syntax in rows add:

JS

table4.rows.add(
   [[ "Tiger Nixon", "System Architect","$3,120" ],
     ["Tiger Nixon", "System Architect", "$3,120" ]]
).draw(); 

查看小提琴更多信息。