【发布时间】:2020-11-23 02:08:01
【问题描述】:
我想在表格外显示导出按钮。
我在 stackoverflow 中看到了一个示例,但这是一种选择选项方法,请参阅该示例 link
如果有人知道该怎么做,请修改它并分享 jsfiddle 链接。
这是我使用 bootstrap4 数据表的代码。
Javasript
$(document).ready(function () {
$("#datatable").DataTable(),
$("#datatable-buttons")
.DataTable( {
lengthChange: !1,
buttons: [
{
extend: 'copy',
text: '<i class="fas fa-copy"></i>',
titleAttr: 'Copy',
className: 'btn btn-md mr-2 btn-copy'
},
{
extend: 'excel',
text: '<i class="fas fa-file-excel"></i>',
titleAttr: 'Excel',
className: 'btn btn-md mr-2 btn-excel'
},
{
extend: 'pdf',
text: '<i class="fas fa-file-pdf"></i>',
titleAttr: 'PDF',
className: 'btn btn-md mr-2 btn-pdf'
},
{
extend: 'print',
text: '<i class="fas fa-print"></i>',
titleAttr: 'Print',
className: 'btn btn-md mr-2 btn-print'
},
{
extend: 'colvis',
text: '<i class="fas fa-eye"></i>',
titleAttr: 'Visibility',
className: 'btn btn-md mr-2 btn-colvis'
},
],
lengthChange: true,
searching: true
})
.buttons()
.container()
.appendTo("#datatable-buttons_wrapper .col-md-6:eq(0)");
});
HTML 代码
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<table id="datatable-buttons" class="table table-striped table-hover table-bordered dt-responsive nowrap"
style="border-collapse: collapse; border-spacing: 0; width: 100%;">
<thead class="thead-dark">
<tr class="text-center">
<th>Id</th>
<th>User Image</th>
<th>Username</th>
<th>Email</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<?php foreach ($userdetails as $key => $userdetail): ?>
<tr>
<td><?php echo $userdetail['id']; ?></td>
<td><?php echo $userdetail['user_image']; ?></td>
<td><?php echo $userdetail['username']; ?></td>
<td><?php echo $userdetail['email']; ?></td>
<td><?php echo $userdetail['role']; ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
</div>
</div>
</div> <!-- end col -->
</div> <!-- end row -->
【问题讨论】:
-
任何人请回答
标签: javascript html datatables