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,
- Part 1: Introduction of Datatable
- Part 2- DataTables Example – Server-side Processing with PHP
- Part 3 – How to add RowId and RowClass on each record using Datatable
- Part 4 – Datatable Pagination, Sorting and Search – Server Side (PHP/MySQl) Using Ajax
- Part5 – Export the jQuery Datatable data to PDF,Excel,CSV and Copy
- Part 6 – Datatable Responsive – Using PHP and Mysql with Ajax
- 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.
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 | 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"/> |
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 | $( document ).ready(function() { |
Adding and customizing Export Button
We can add and customize Export Button using button
json
object.1 | "buttons": [ |
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