Silahkan Melihat Tutorial di website kami dengan nyaman ENJOY YOUR LIFE ☕

PHP :: How to Export the jQuery Datatable data to PDF,Excel,CSV and Copy


In This Post I will show you Exporting functionality with Datatable,PHP and MySQL.I Got huge response from readers on datatable with php tutorials,One of my reader request tutorial about datatable with export features.I have research and found that there are two option to add export features into datatable.
Also Checkout other tutorial of Datatable,
  • Tabletools Plugin : This plugin is used to export table data into pdf,xls,csv etc. using swf object but right its out dated.
  • ExportButton Plugin : This plugin used to export table data into pdf,xls,csv etc. using HTML5.
datatable-with-export-data
So i have taken option 2, I am integrating Export Button on Datatable with PHP.
i got one more issue with export Button datatable plugin,You can not get full export data into pdf,excel etc. using ajax request,You can get only visible records into exported pdf,excel etc file.
I have used NON ajax manner to export datatable data with PHP.

Export DataTable Data Using Button Plugin and PHP

In this post I will demonstrate, how to add Export functionality in datatable using Export Button Plugin.You can export data in CSV,PDF,Excel etc format as well as Copy the table data into clipboard.Please keep in mind these functionality will work only HTML5 supported browser.

We will cover following functionality in this Datatable Tutorial

  • Load one time data into table
  • Export and Save Datatable data into CSV
  • Export and Save Datatable data into PDF
  • Export and Save Datatable data into Excel
  • You can Copy datatable data into clipboard
  • You can Print the datatable data

Adding Necessary jQuery Datatable library and Plugins

We will include all necessary plugin and library files to export data from datatable.
1
2
3
https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.css"/>

<script type="text/javascript" src="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.js"></script>
We have used Datatable download builder tools generated js and css files.

Initialization Of dataTable on HTML Table

We can initialize export Button by simply adding ‘B’ into DOM element.
1
2
3
4
5
6
7
8
$( document ).ready(function() {
$('#employee_grid').DataTable({
"processing": true,
"sAjaxSource":"response.php",
"dom": 'lBfrtip',

});
});

Adding and customizing Export Button

We can add and customize Export Button using button json object.
1
2
3
4
5
6
7
8
9
10
11
12
13
"buttons": [
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
]
Here we passed copy,excel,csv,pdf and print options into 'button' JavaScript array.This will contains all options button which you want show under Export Button.I have changed default button text to“Export” using “text” option.
The server code is same is my previous Datatable with PHP,mysql and Ajax article.
You can download source code and Demo from below link.




0 komentar:

Post a Comment

PHP :: How to Export the jQuery Datatable data to PDF,Excel,CSV and Copy