15

I have a table using datatables plug-in. I'm trying to make my table header fixed, and follow this link : here

$('.device-table').DataTable( {
    "fixedHeader": {
        header: true,
    },
    "bLengthChange": false,
    "Filter": false,
    "Info": false,
} );

I don't see the effect. I've included both js files of datatables and fixedHeader:

<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/fixedheader/3.1.2/js/dataTables.fixedHeader.min.js" type="text/javascript"></script>

How would one go about and debug this?

4
  • Can you please make a quick fiddle with your code and share us the link to debug? Commented Nov 1, 2016 at 13:51
  • Did you check the jsfiddle? it doesn't work... check the console for errors Commented Nov 1, 2016 at 13:59
  • double check again? please make sure next time it really works... Commented Nov 1, 2016 at 14:22
  • Try this one : jsfiddle.net/bheng/s2xbf9d0/5/show Commented Nov 1, 2016 at 14:33

2 Answers 2

28

For the fixedHeader plugin to work you also need the css file:

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/fixedheader/3.1.2/css/fixedHeader.dataTables.min.css">

Check this update:
https://jsfiddle.net/s2xbf9d0/6/

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

2 Comments

I added your suggestion and still didn't see it. Check it out here = jsfiddle.net/bheng/s2xbf9d0/10
You are messing the the styles :) remove the height: 150px; you have in the css and set scrollY: '150px' in the DataTable constructor instead. Check here: jsfiddle.net/s2xbf9d0/11
6

Your fiddle seems to be missing the dataTables.fixedHeader plugin as well as the fixedHeader.dataTables CSS file which was causing you the page from rendering properly (with the fixed headers).

Working DEMO: - https://jsfiddle.net/s2xbf9d0/7/

Hope this helps!

1 Comment

After scroll, the table won't stay !! See this : jsfiddle.net/bheng/s2xbf9d0/9

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.