DataTables - Exporting Headers with HTML
HTML
<link rel="stylesheet" href="//cdn.datatables.net/1.10.8/css/dataTables.jqueryui.min.css">
<link rel="stylesheet" href="//cdn.datatables.net/buttons/1.0.1/css/buttons.jqueryui.min.css">
<script src="//cdn.datatables.net/1.10.8/js/jquery.dataTables.min.js"></script>
<script src="//cdn.datatables.net/1.10.8/js/dataTables.jqueryui.min.js"></script>
<script src="//cdn.datatables.net/buttons/1.0.1/js/dataTables.buttons.min.js"></script>
<script src="//cdn.datatables.net/buttons/1.0.1/js/buttons.jqueryui.min.js"></script>
<script src="//cdn.datatables.net/buttons/1.0.1/js/buttons.flash.min.js"></script>
<script src="//cdn.datatables.net/buttons/1.0.1/js/buttons.html5.min.js"></script>
<script src="//cdn.datatables.net/buttons/1.0.1/js/buttons.print.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
<script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
<table width="100%" class="display" id="example" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
...
CSS
body {
font: 90%/1.45em"Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
color: #333;
background-color: #fff;
}
div.container {
min-width: 980px;
margin: 0 auto;
}
JavaScript
$(document).ready(function () {
var table = $('#example').DataTable({
dom: "Blfrtip",
buttons: [
{
extend: "copy",
exportOptions: {
stripHtml: false
}
},
{
extend: "csv",
exportOptions: {
stripHtml: false
}
},
{
extend: "excel",
header: true,
exportOptions: {
stripHtml: false
}
},
{
extend: "pdf",
exportOptions: {
stripHtml: false
}
}
]
});
});