0

Here, I have one table, i want to fix that header while scrolling

JS

<script>
$('#scroll').scroll(function(){
if ($('#scroll').scrollTop() > 10){
    $("thead").css({
            position: 'fixed',
            top: '68px'
        });
}else{
    $('thead').css({
        position: 'static'
    });
}
});
</script>

This is working Perfectly, but design is changing.

LIVE DEMO

could anyone help me out.

Thanks in advance.

EDIT

Fiddle

4
  • I believe it is happening because of position: 'fixed' try changing it to static and it might wok. Commented Dec 5, 2013 at 6:03
  • 1
    Why you wont try to use datatables.net/extras/fixedheader or tablefixedheader.com or fixedheadertable.com Commented Dec 5, 2013 at 6:03
  • can anyone make example Commented Dec 5, 2013 at 6:05
  • @NareshKamireddy check out my answer bub, try using my piece of code Commented Dec 5, 2013 at 6:06

4 Answers 4

1

You can use datatables plugin with different table types(fixed header table, example)

Sign up to request clarification or add additional context in comments.

Comments

1

I got solution for fixed header, i used http://fixedheadertable.com/.

Thank you for your support

Comments

0

Position: fixed will ignore all other markup on the page and position your element relative to the browser window. Regardless of the markup I think you'll want to use position: absolute and apply position: relative to the table's containing element.

example: http://jsfiddle.net/QxW6v/1/

5 Comments

can you give some example
Set #scroll to position: relative and have your jQuery set <thead> to position: absolute instead of fixed on scroll. You'll need to add left: 0; right: 0; to the thead element as well.
in that case header is not freezing
and you left <thead> as top: 68px?
jsfiddle.net/cqDC5/2 this is as close as I'm going to get, you've added pixel dimensions to all your th and tds which forces the header to be wider than its container. Get rid of those and you should be ok.
0
   <script>
$('#scroll').scroll(function(){
if ($('#scroll').scrollTop() > 10){
    $("thead").css({
            position: 'static',
            top: '68px'
        });
}else{
    $('thead').css({
        position: 'static'
    });
}
});
</script>

Use this, you are changing position of header to fixed while scrolling, which is causing the issue

5 Comments

@NareshKamireddy your heading is having fixed position while being scrolled, in my opinion that is causing the issue. it should be either static or relative.
Here i want to fix the header and design also, both i need
by fix do u mean fixed position or do u want it to stay where it is while scrolling?
header is not freezing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.