Advertisement
imjyb1008work

利用row.add()增加資料

Jan 21st, 2020
1,724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.66 KB | None | 0 0
  1. <table id="dataTable">
  2.     <thead>
  3.         <tr>
  4.             <th>座號</th>
  5.             <th>姓名</th>
  6.             <th>性別</th>
  7.         </tr>
  8.     </thead>
  9.     <tbody>
  10.     </tbody>
  11. </table>
  12.  
  13. <script>
  14.     var table = $("#dataTable").DataTable();
  15.  
  16.     var students = [
  17.         { id: 1, name: "Justin", gender: "男" },
  18.         { id: 2, name: "Kevin", gender: "男" },
  19.         { id: 3, name: "Karen", gender: "女" },
  20.         { id: 4, name: "Lucy", gender: "女" },
  21.     ];
  22.  
  23.     students.forEach(function (element) {
  24.         table.row.add([
  25.             element.id,
  26.             element.name,
  27.             element.gender
  28.         ]);
  29.     });
  30. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement