下載位置
HTML 部份
<table id="example">
<thead>
<tr><th>head1</th><th>head2</th><th>head3</th>
</thead>
<tbody>
<tr>
<td>body1</td>
<td>body2</td>
<td>body3</td>
</tr>
<tr>
<td>body1-1</td>
<td>body2-2</td>
<td>body3-3</td>
</tr>
<tr>
<td>body1-1-1</td>
<td>body2-2-2</td>
<td>body3-3-3</td>
</tr>
</tbody>
</table>
JS 部份
$("#example").DataTable({
order:[0,'desc'], //排序方式跟排序column
columnDefs: [{
"targets":[1],
"visible":false,
"searchable":false
}], //設定 column 1 為不可見 及不能被搜尋
dom:'Bftrip',
buttons: [{
extend: 'excel',
exportOptions:{
columns:[0,1,2]
}
},
{
extend: 'pdf',
exportOptions:{
columns:[0,1,2]
}
},
{
extend: 'csv',
exportOptions:{
columns:[0,1,2]
}
}
] //設定匯出的格式及 匯出的column
});
更多詳情
https://datatables.net/extensions/buttons/examples/initialisation/export.html