JSFiddle - React, Tailwind, and code Playground
by Shuaib Khan
HTML
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.4/js/dataTables.buttons.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
<script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
<script src="//cdn.datatables.net/buttons/1.2.4/js/buttons.html5.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.4/css/buttons.dataTables.min.css">
<title>Example 1 - apply dataTable()</title>
<div class="actionPart" >
<div class="actionSelect">
<select id="exportLink">
<option>Export userlist</option>
<option id="csv">Export as CSV</option>
<option id="excel">Export as XLS</option>
<option id="copy">Copy to clipboard</option> <option id="pdf">Export as PDF</option>
</select>
</div>
</div>
<table class="display" id="example">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th data-orderable="false">Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System...
JavaScript
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5'
],
initComplete: function() {
var $buttons = $('.dt-buttons').hide();
$('#exportLink').on('change', function() {
var btnClass = $(this).find(":selected")[0].id
? '.buttons-' + $(this).find(":selected")[0].id
: null;
if (btnClass) $buttons.find(btnClass).click();
})
}
} );
} );