小编Kri*_*hna的帖子

如何在datatables jquery中添加多行

我使用https://datatables.net/reference/api/rows.add%28%29链接工作,但数据显示表格为[object,object].如何将对象显示为字符串.我用过JSON.stringify(obj)它也没用.

HTML

<table id="exampleTable">
 <thead>
  <tr>
   <th>Year</th>
   <th>Month</th>
   <th>Savings</th>
  </tr>
 </thead>
 <tbody>
   <tr>
    <td>2012</td>
    <td>January</td>
    <td>$100</td>
   </tr>
   <tr>
    <td>2012</td>
    <td>February</td>
    <td>$80</td>
   </tr>
 </table>
Run Code Online (Sandbox Code Playgroud)

JS

$('#addRows').click(); 

var table3 = $('#exampleTable').DataTable(); 

$('#addRows').on( 'click', function () { 
    table3.row.add(
       [ { "Year": "Tiger Nixon", "Month": "System Architect", "Savings": "$3,120" },
         {"Year": "Tiger Nixon", "Month": "System Architect", "Savings": "$3,120" }]
    ).draw(); 
});
Run Code Online (Sandbox Code Playgroud)

jquery jquery-datatables datatables-1.10

13
推荐指数
2
解决办法
3万
查看次数