When using the sScrollX
, sScrollXInner
and/or sScrollY
to achieve a fixed header table with its inner content scroll
try this, the following code solved my problem
table.dataTable tbody th,table.dataTable tbody td
{
white-space: nowrap;
}
for more information pls refer Here.
Faced the same issue recently and was still searching for the solution when I tried something on my css, check if adding to your cells (th and td)
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
-sizing: content-box;
will resolve this issue; for me, I was using some html/css framework that was adding a the value border-box
in every element.
EDIT: See the latest Fiddle with "fixed header":
The Fiddle.
One of the solutions is to implement scrolling yourself instead of letting DataTables plugin do it for you.
I've taken your example and commented out sScrollX option. When this option is not present DataTables plugin will simply put your table as is into a container div. This table will stretch out of the screen, therefore, to fix that we can put it into a div with required width and an overflow property set - this is exactly what the last jQuery statement does - it wraps existing table into a 300px wide div. You probably will not need to set the width on the wrapping div at all (300px in this example), I have it here so that clipping effect is easily visible. And be nice, don't forget to replace that inline style with a class.
$(document).ready(function() {
var stdTable1 = $(".standard-grid1").dataTable({
"iDisplayLength": -1,
"bPaginate": true,
"iCookieDuration": 60,
"bStateSave": false,
"bAutoWidth": false,
//true
"bScrollAutoCss": true,
"bProcessing": true,
"bRetrieve": true,
"bJQueryUI": true,
//"sDom": 't',
"sDom": '<"H"CTrf>t<"F"lip>',
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
//"sScrollY": "500px",
//"sScrollX": "100%",
"sScrollXInner": "110%",
"fnInitComplete": function() {
this.css("visibility", "visible");
}
});
var tableId = 'PeopleIndexTable';
$('<div style="width: 300px; overflow: auto"></div>').append($('#' + tableId)).insertAfter($('#' + tableId + '_wrapper div').first())});
I fixed the same issue in my application by adding below code in the css -
.dataTables_scrollHeadInner
{
width: 640px !important;
}
Add table-layout: fixed
to your table's style (css or style attribute).
The browser will stop applying its custom algorithm to solve size constraints.
Search the web for infos about handling column widths in a fixed table layout (here are 2 simple SO questions : here and here)
Obviously: the downside will be that your columns' width won't adapt to their content.
[Edit] My answer worked when I used the FixedHeader plugin, but a post on the datatable's forum seem to indicate that other problems arise when using the sScrollX
option :
bAutoWidth and sWidth ignored when sScrollX is set (v1.7.5)
I'll try to find a way to go around this.
After trying everything I could, I just added "autoWidth": true
and it worked for me.