DataTables#2 - sDom option custom header
Create a custom header.
by litespeedtdf
HTML
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css">
<script src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.0.3/js/dataTables.buttons.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.0.3/css/buttons.dataTables.min.css">
<script src="https://cdn.datatables.net/buttons/1.0.3/js/buttons.print.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.0.3/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.0.3/js/buttons.flash.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.0.3/css/buttons.bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<table id="example" class="display" width="100%">
<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>$3,120</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Director</td>
<td>Edinburgh</td>
<td>63</td>
<td>2011/07/25</td>
<td>$5,300</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$4,800</td>
</tr>
...
CSS
div.dataTables_info, div.dataTables_length {
float:left;
width:auto;
/*padding-right:1em;*/
}
div.dataTables_wrapper div.dataTables_filter {
float:right;
width:auto;
/* position: absolute;*/
padding-left:15px;
}
#ordStatusFilter {
float:left;
/* position: relative;
width:auto;*/
padding-right:2em;
width:auto;
}
div.dataTables_filter .dt-buttons {
float:left;
width:auto;
/* position: fixed;
padding-right:1em;
padding-left:1em;*/
}
.toolbar {
width:auto;
}
JavaScript
$(document).ready(function () {
var table = $('#example').DataTable({
"sDom": '<"toolbar"Bf>t<"bottom"ip<"clear">>',
'buttons': [
'copyFlash',
'excelFlash',
'pdfFlash',
'print'
],
"headerCallback": function (thead, data, start, end, display) {
//$('#j1').append($('.dt-buttons'));
//$('#example_wrapper').find('.dataTables_filter').prepend($('#j1')); //.append($('.dt-buttons'));
},
"initComplete": function (settings, json) {
$('#example_wrapper').find('.toolbar').prepend($('#ordStatusFilter'));
//$('#j1').after($('.dt-buttons'));
}
});
});