jquery datatable export table to PDF/Excel demo
jquery datatable export table to PDF/Excel demo
HTML
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.18/css/jquery.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.5.6/css/buttons.dataTables.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.html5.min.js"></script>
<table id="example" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Test</th>
</tr>
</thead>
</table>
JavaScript
var data = [];
for ( var i=0 ; i < 10000 ; i++ ) {
data.push(
[
i, 'This is a very long sentence to test whether datatables PDF export works efficiently with a large dataset. Additionally I have nothing else to say but need more data to test so I will continute to write and see if perhaps I can break it.'
]
);
}
$('#example').dataTable({
dom: 'Bfrtip',
data: data,
buttons: [
'csv', 'excel', 'pdf'
]
});