且构网

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

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

更新时间:2023-12-01 18:51:46

我在这个 FIDDLE 中创建了两个示例一>.

I created two samples in this FIDDLE.

如果你想在行添加中使用对象,你应该在你的数据表初始化中添加列:

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

但如果您不想这样做,您可以在行添加中使用下一个语法:

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

看看 fiddle 内容更丰富.