Freeze table columns – DataTables

Fixed table

Today I’ll show you how can you freez table columns/rows on website in simple way. The best for it will be another great and powerful tool plug-in for JQuery library DataTables.


In our example we need to include some scripts and styles like this:

<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<link rel="stylesheet" type="text/css" href="" />

First is JQuery script, lines 2-3 is plug-in for JQuery DataTables and the last is stylesheet for our library.

Operating principle is simple.On our table, we use the function “DataTable”.Then we set properties which we are interested in.

In our example it look like:

$(document).ready(function() {
    var table = $('#tab').DataTable( {
        scrollY:        "400px",
        scrollX:        true,
        scrollCollapse: true,
        paging:         false,
        fixedColumns:   {
            leftColumns: 1,
    } );

For the purpose of our example we set max height scroll to 400px.We can also set – how many columns we are freezing(7-8th line), we want paging in our table or not(6th line), etc.

Let’s see how it look on our ready-made sample table. HERE

Of course, we have more opportunity.If you want to know more options I refer you to the examples on the official website of this library.

Link to the project.


Leave a Reply

Your email address will not be published. Required fields are marked *