Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7612801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:00:24+00:00 2026-05-31T02:00:24+00:00

Please see my jsfiddle i’ve created to replicate my problem. http://jsfiddle.net/motocomdigital/22KFS/3/ In my project,

  • 0

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>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:00:26+00:00Added an answer on May 31, 2026 at 2:00 am

    Solved your problem. In case you hadn’t realised already, the reason it jumps is because you are essentially removing the header row from the table when you make it position fixed, so the rest of the table jumps up to fill the gap.

    The solution? Well, it’s up for debate. To prove my point, all I’ve done is add a new temporary header when you make the actual header fixed. This keeps the table in place and allows the header to move down. When you scroll back up, that temporary header then gets removed.

    Is this the best way? Not sure, you maybe want to clone the real header as a temporary solution, just in case of graphical glitches. This would also mean that in case of headers with multiple lines (therefore pushing the height down), the effect would be maintained as it’s taking an exact clone.

    Anyway, on with the code: http://jsfiddle.net/chricholson/22KFS/5/

    $("#table-sorter").tablesorter({
     widgets: ['zebra']
    });
    
    
    var $window     = $(window),
        $tableHead  = $(".table-head"),
        offset      = $tableHead.offset();
    
    $window.scroll(function() {
    
    
        if ($window.scrollTop() > offset.top) {
            $tableHead.addClass('fixed');
            if ($('#table-sorter thead tr.temp').length <= 0){
                $('#table-sorter thead').append('<tr class="temp"><td>hello</td></tr>');
            }
        } else {
            $tableHead.removeClass('fixed');
            $('tr.temp').remove();
        }
    
    
    }); 
    

    ​
    Good luck.

    EDIT

    Here’s the working product using clone()
    http://jsfiddle.net/chricholson/22KFS/8/

    Code:

    $("#table-sorter").tablesorter({
         widgets: ['zebra']
    });
    
    
    var $window     = $(window),
        $tableHead  = $(".table-head"),
        offset      = $tableHead.offset();
    
    $window.scroll(function() {
    
    
        if ($window.scrollTop() > offset.top) {
            $tableHead.addClass('fixed');
            if ($('#table-sorter thead tr.temp').length <= 0){
                $tableHead.clone().appendTo('#table-sorter thead').removeClass('fixed').addClass('temp');
            }
        } else {
            $tableHead.removeClass('fixed');
            $('tr.temp').remove();
        }
    
    
    });    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see http://jsfiddle.net/jGCx9/ I have right: 28px which causes the span element to shift
Please see: http://jsfiddle.net/XEbKy/3/ I have two layers of tabs. On the top layer I
Please see this jsFiddle: https://jsfiddle.net/Wmq6f/ I have a textarea that has a background image,
Please see this: http://jsfiddle.net/uNbYu/1/ If you click submit, the button doesn't do anything, but
please see this example http://jsfiddle.net/7trcV/ what I'm trying to achieve is ability to put
Please see my source code at: http://jsfiddle.net/rAmSG/9/ The blue item should be dropped at
Please see http://jsfiddle.net/jaWjB/1/ The line break happens in between the second image and its
please see my fiddle: http://jsfiddle.net/qVHg8/1/ Why isn't the fixedRightCol being positioned at right:0 of
please see: http://jsfiddle.net/4Z4fQ/19/ consider the following html: <a id=myElement href=http://www.google.com/> <img id=image src=http://www.google.com/intl/en_com/images/srpr/logo3w.png alt=google/>
Please see http://jsfiddle.net/mithun/nuF2Q/1/ I've the HTML structure <div id='slider'> <ul> <li> <a class='pride' href=i1.html>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.