I want to display the export buttons in outside the table.
I saw one example in stackoverflow but that's is a Select options method see that example link
If anyone knows how to do that mean please modify it and share jsfiddle link.
Here is my code Im using bootstrap4 datatable.
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 Code
<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 -->