Please see my jsfiddle i've created to replicate my problem. http://jsfiddle.net/motocomdigital/22KFS/3/
In my project, I have created a table, which is sortable. I've used the jquery table sorter to do this which is a very simple jquery plugin. The table sorter is also included in the jsfidde. If you click the table headers, you will notice it sorts the table columns from descending to ascending.
This is fine, the problem I have is...
On my live website, the table is about 125 rows high. And I want to avoid paginating the table at all costs.
So my idea was to fix the table header upon scrolling with jQuery, which is nearly working. Please see my fiddle. The jQuery I've used to fix the header to the top of the pages works.
The problem is because the table header becomes fixed, the table shifts up a row, and makes it very glitchy.
Can anyone help me remove the glitchness, and stop it skipping a row when it reaches the top of window.
Would really appreciate any help thanks.
See jsfiddle here http://jsfiddle.net/motocomdigital/22KFS/3/
jQuery
var $window = $(window),
$tableHead = $(".table-head"),
offset = $tableHead.offset();
$window.scroll(function() {
if ($window.scrollTop() > offset.top) {
$tableHead.addClass('fixed');
} else {
$tableHead.removeClass('fixed');
}
});
CSS
.fixed {
position: fixed;
top: 0;
}
HTML
<table id="table-sorter" width="400" border="0" cellspacing="0" cellpadding="10">
<thead>
<tr class="table-head">
<th width="100" height="18" valign="middle">Number</th>
<th width="100" height="18" valign="middle">First Name</th>
<th width="100" height="18" valign="middle">Surname</th>
<th width="100" height="18" valign="middle">System</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>Smith</td>
<td>Wordpress</td>
</tr>
... ...
</tbody>
</table>