How to add multiple rows in datatables jquery

后端 未结 4 1322
旧时难觅i
旧时难觅i 2021-01-01 22:21

I have used https://datatables.net/reference/api/rows.add%28%29 link working but the data showing the table as [object,object]. How to show the object to string

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 22:52

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

    Look fiddle it's more informative.

提交回复
热议问题