Hi I am using jQuery Datatables 1.10. I am trying to export Datatable multiple header rows but not getting. But it is Exporting only second header row. I am using Buttons:
buttons: [{
extend: 'excel',
header: true
}, {
extend: 'print',
header: true
}],
My table Structure like
<table id="example" style="color: black;" class="display compact cell-border" cellspacing="0">
<thead>
<tr>
<th rowspan="2">Sl.No</th>
<th rowspan="2">Zone</th>
<th colspan="2">Allotted</th>
<th colspan="2">Vacant</th>
<th colspan="2">Amenities</th>
<th colspan="2">Total</th>
</tr>
<tr>
<th>No Of Plots</th>
<th>Area</th>
<th>No Of Plots</th>
<th>Area</th>
<th>No Of Plots</th>
<th>Area</th>
<th>No Of Plots</th>
<th>Area</th>
</tr>
</thead>
</table>
The mentioned solution on the DataTable-forum is not working for the latest version. I have adapted it in a way it works for me. I added a local function to buttons.html5.js:
Then I changed the code in
DataTable.ext.buttons.excelHtml5
in the same file to:Adding to the solution that was given by Ronnie, since most of us got confused how exactly the approach works, would like to take it in a detail.
To get Excel button working add
buttons.html5.js
,dataTables.buttons.min.js
,jszip.min.js
.For multiple row header table export, add below function in
buttons.html5.js
at the bottom of the documentWith in the same file find
DataTable.ext.buttons.excelHtml5
and replace the code blockto
That's it. you would be able to export the multiple header rows.
And adding to the above if you want to export merged cells then below code would help you.
Add this to buttons customize function.
Better to check this datatable documentation.Find below URL Export multiple row headers
I've created a custom buttons.html5.js (based in Ronnie's solution) that allows Multiple Headers and Footers in Excel export
https://gist.github.com/emersonmoretto/41993309f74a4b09f8e90c0a541de342
Answer by @ronnie https://stackoverflow.com/a/42535830/5835910 is working. To make it work download the files from jquery datatable download builder https://datatables.net/download/index.
Please do not use files from example pages.
Hi maybe I'm a little late but I hope my answer can help someone else. I exported all rows using an extra library, in my case, table2excel. I just copied the header rows using html() function and getting all the rows with .DataTable() function. The code looks as follows:
It solved the problem in my case.