Html table with fixed header and fixed column both
I finally Got the answer, I used the https://github.com/meetselva/fixed-table-rows-cols
Here is the working fiddle http://jsfiddle.net/cfr94p3w/17/
It's simple to use. Just take normal HTML table and apply the plugin
JS: https://rawgit.com/meetselva/fixed-table-rows-cols/master/js/fixed_table_rc.js
css: https://rawgit.com/meetselva/fixed-table-rows-cols/master/css/fixed_table_rc.css
$(document).ready(function() {
$('#fixedHeader').fxdHdrCol({
fixedCols: 2,
width: "100%",
height: 400,
colModal: [
{ width: 100, align: 'center' },
{ width: 70, align: 'center' },
{ width: 70, align: 'left' },
{ width: 70, align: 'left' },
{ width: 70, align: 'left' },
{ width: 70, align: 'left' },
{ width: 70, align: 'left' },
{ width: 70, align: 'center' },
],
});
});
PS: Thanks everybody, mostly 'Bas van Stein' for the assistance.
How do I create an HTML table with a fixed/frozen left column and a scrollable body?
If you want a table where only the columns scroll horizontally, you can position: absolute
the first column (and specify its width explicitly), and then wrap the entire table in an overflow-x: scroll
block. Don't bother trying this in IE7, however...
Relevant HTML & CSS:
table {
border-collapse: separate;
border-spacing: 0;
border-top: 1px solid grey;
}
td,
th {
margin: 0;
border: 1px solid grey;
white-space: nowrap;
border-top-width: 0px;
}
div {
width: 500px;
overflow-x: scroll;
margin-left: 5em;
overflow-y: visible;
padding: 0;
}
.headcol {
position: absolute;
width: 5em;
left: 0;
top: auto;
border-top-width: 1px;
/*only relevant for first row*/
margin-top: -1px;
/*compensate for top border*/
}
.headcol:before {
content: 'Row ';
}
.long {
background: yellow;
letter-spacing: 1em;
}
<div>
<table>
<tr>
<th class="headcol">1</th>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<th class="headcol">2</th>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<th class="headcol">3</th>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<th class="headcol">4</th>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<th class="headcol">5</th>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<th class="headcol">6</th>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
</table>
</div>
Table fixed header and scrollable body
Here is the working solution:
table { width: 100%;}
thead, tbody, tr, td, th { display: block; }
tr:after { content: ' '; display: block; visibility: hidden; clear: both;}
thead th { height: 30px;
/*text-align: left;*/}
tbody { height: 120px; overflow-y: auto;}
thead { /* fallback */}
tbody td, thead th { width: 19.2%; float: left;}
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-striped"> <thead> <tr> <th>Make</th> <th>Model</th> <th>Color</th> <th>Year</th> </tr> </thead> <tbody> <tr> <td class="filterable-cell">Ford</td> <td class="filterable-cell">Escort</td> <td class="filterable-cell">Blue</td> <td class="filterable-cell">2000</td> </tr> <tr> <td class="filterable-cell">Ford</td> <td class="filterable-cell">Escort</td> <td class="filterable-cell">Blue</td> <td class="filterable-cell">2000</td> </tr> <tr> <td class="filterable-cell">Ford</td> <td class="filterable-cell">Escort</td> <td class="filterable-cell">Blue</td> <td class="filterable-cell">2000</td> </tr> <tr> <td class="filterable-cell">Ford</td> <td class="filterable-cell">Escort</td> <td class="filterable-cell">Blue</td> <td class="filterable-cell">2000</td> </tr> </tbody></table>
Related Topics
Detect Rotation of Android Phone in the Browser with JavaScript
Is It Safe to Store a Jwt in Localstorage with Reactjs
Get Average Color of Image via JavaScript
How to Check If a JavaScript Object Is a Dom Object
JavaScript Filter Array Multiple Conditions
Why How to Use a Function Before It's Defined in JavaScript
Request Header Field Access-Control-Allow-Headers Is Not Allowed by Access-Control-Allow-Headers
What Is the Minimum Valid JSON
Get Mouse Wheel Events in Jquery
How to Download a File Using Window.Fetch
What Does the "|" (Single Pipe) Do in JavaScript
\U200B (Zero Width Space) Characters in My Js Code. Where Did They Come From
Drop-Down Box Dependent on the Option Selected in Another Drop-Down Box
Get Value of Input Field Inside an Iframe
Template Does Not Update When Using Ui-Router and Ion-Tabs