Export Buttons In Datatable
In this example I will show you how to add export buttons in datatable laravel, If you want to export datatable data in excel, pdf or csv file format, then you have to add export button in datatable.
Datatables provide DataTable Buttons plugin for add export button in datatable. After adding of export button, you can easily export data to CSV file or Excel sheet file, pdf file and also you can copy all datatable data in html format. The HTML5 export buttons plug-in for Buttons provides four export buttons like copyHtml5, csvHtml5, excelHtml5, pdfHtml5.
You need to simply add below javascript cdn to add export button in datatable.
https://code.jquery.com/jquery-3.5.1.js
https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js
https://cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js
https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js
https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js
https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js
https://cdn.datatables.net/buttons/1.6.2/js/buttons.html5.min.js
Read Also : Remove/Hide Columns While Export Data In Datatable
And also add following CSS library files are loaded for use in this example to provide the styling of the table:
https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css
https://cdn.datatables.net/buttons/1.6.2/css/buttons.dataTables.min.css
Add below javascript code in your script tag.
$(document).ready(function() {
$('#export_example').DataTable( {
dom: 'Bfrtip',
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5'
]
} );
} );
You might also like :