Datatable with fixed header
Test for datatable with fixed header in scrolling-container
HTML
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/dataTables.jqueryui.min.js"></script>
<script src="https://cdn.datatables.net/fixedheader/3.1.2/js/dataTables.fixedHeader.min.js"></script>
<script src="https://cdn.rawgit.com/ecomfe/echarts/master/dist/echarts.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/dataTables.jqueryui.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/fixedheader/3.1.2/css/fixedHeader.jqueryui.min.css">
<body>
<div id="pageHeader">
<div style='display:inline-block;float:left;margin-left:20px;margin-top:5px;'>
<img src='https://datatables.net/media/images/logo-fade.png '>
</div>
<div style='display:inline-block;vertical-align:top;margin-left:20px;'><h2>Header</h2></div>
<div style='clear:both;float:none;display:block;position:relative;'></div>
</div>
<div id="wrap">
<div id="contentMain">
<div id="mainBar" style="height:300px;border:1px solid #ccc;padding:10px;"></div>
<div id="datTabl" style="height:500px;border:1px solid #ccc;padding:10px;">
<table width="100%" class="display" id="dTable1" 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>
<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
* {margin:0;padding:0}
p{margin:0 0 1em 0}
html,body{margin:0;padding:0}
body{
height:100%;
}
html>body{
position:absolute;
width:100%;
left:0%;
margin-left:0px;
}
#pageHeader {
background:Gainsboro;
position: fixed;
left: 0; right: 0;top:0;
height: 100px;
z-index:11;
}
#pageFooter {
background:Gainsboro;
position: fixed;
left: 0; right: 0;bottom:0;
height: 24px;
}
#contentMain{
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
background:white;
position:relative;
margin-top:2px;
margin-bottom:2px;
margin-left:2px;
margin-right:2px;
}
#pageHeader {
background:Gainsboro;
position: fixed;
left: 0; right: 0;top:0;
height: 100px;
z-index:11;
}
#contentMain{
background:white;
overflow:auto;
position:relative;
margin-top:2px;
margin-bottom:2px;
margin-left:2px;
margin-right:2px;
}
JavaScript
$(document).ready(function() {
$('#dTable1').DataTable( {
fixedHeader: {
header: true,
headerOffset: $('#pageHeader').outerHeight()
}
} );
});