1

I m working with datatables for the first time and got struck with the below explained issue.. Whenever i m trying to include vertical scroll , column headers losses all itz alignment, all the column width reduces and as a result will get header row who's length is half of the entire table.

One more thing i ve noticed is that, in the th class style width is coming as 0px, can any one pls temme why it's coming so ? js part i ve included,

$(document).ready(function() {

                $.ajax({
                    type : "GET",
                    url :"",

                    dataType : "json",
                    success : function(data) 
                    {
                            $('#customers').dataTable(
                            {
                            "aaData":data.response,
                            "aoColumns": [
                            { "sTitle": "Rendering Engine", "bSortable": false},
                            { "sTitle": "Broswers", "bSortable": false },
                            { "sTitle": "Platform", "bSortable": false }
                            ],
                         "sScrollY": "250px",
                        "iDisplayLength": 200,
                        "bFilter": false,
                        "bLengthChange": false,
                        "bAutoWidth": false
                           });
                    }   
                });
            });

and html part

<table id="customers"></table>    

Thanks in Advance !

1
  • If it's not just a typo, you've messed up with the quotes ? Three quotes in 'url' will start a new string that now inludes dataType etc... Commented Jul 23, 2012 at 7:15

3 Answers 3

4

I solved this problem by wrapping the "dataTable" Table with a div with overflow:auto

.dataTables_scroll
{
    overflow:auto;
}

and add this JS after your dataTable initialization

jQuery('.dataTable').wrap('<div class="dataTables_scroll" />');

Dont use sScrollX or sScrollY, remove then and add a div wrapper yourself which does the same thing.

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

2 Comments

For printing issue also add @media print{ .dataTables_scroll{overflow:visible!important;} }
This doesn't work, as now the header is part of the single table and will scroll with the rest of the table body.
0
    success : function(data) 
                {
                        $('#customers').dataTable(
                        {
                        "aaData":data.response,
                        "aoColumns": [
                        { "sTitle": "Rendering Engine", "bSortable": false},
                        { "sTitle": "Broswers", "bSortable": false },
                        { "sTitle": "Platform", "bSortable": false }
                        ],
                     "sScrollX": "100%",
                     "sScrollY": "250px",
                    "iDisplayLength": 200,
                    "bFilter": false,
                    "bLengthChange": false,
                    "bFilter": true,
                    "bSort": true,
                    "aLengthMenu": [50,100,250,500],
                    "sPaginationType": "full_numbers"
                       });
                }   





  //use this style
 <style type="text/css">

       .dataTables_length {
       float: left;
       width: 40%;
        }

    .dataTables_filter {
      float: right;
      text-align: right;
      width: 50%;
      } 

  .dataTables_info {
   float: left;
   width: 50%;
  vertical-align: middle;
  /*min-height: 100%;*/
  /*position: absolute;*/
  }
</style>

1 Comment

The problem with the column headers is that ..once the scroll is added ,the column headers are coming as a table of width 0px.. I m getting confused of how to manage the styles of tht table
0

The problem is that your table is empty. I've seen similar issues in the past, they were always caused by your table not having a <thead> / <tbody>.

Change your HTMl to:

<table id="customers">
    <thead>
    </thead>
    <tbody>
    </tbody>
</table>

Let me know what happens.

Comments

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.