Issue with % width on parent when using sScrollY = "XXXpx"
Issue with % width on parent when using sScrollY = "XXXpx"
Hi,
I have this issue where the column headings width(s) never changing when I set sScrollY to anything. The actual data within the table scales just fine. This will ONLY occur when the parent of the datatable is set to be a relative width to say the document (like "
I have this issue where the column headings width(s) never changing when I set sScrollY to anything. The actual data within the table scales just fine. This will ONLY occur when the parent of the datatable is set to be a relative width to say the document (like "
This discussion has been closed.
Replies
[code]
function BasicDataTable(tableId) {
return $('#' + tableId).dataTable({
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"bInfo": true,
"bAutoWidth": true,
"sDom": 'lfrtip',
"sScrollY": "200px", //height
"bScrollCollapse": true,
"oLanguage": {
"sInfo": ""//remove "Showing X to Y of Z entries"
},
//HACK ALERT!! for whatever reason datatables doesn't work well with "stretchy" parent elements specifically when "sScrollY" is set, the header gets messed up
//on parent resize. the below fixes this making the table fully stretchable
"fnInitComplete": function () {
var tableWrapper = $('#' + tableId + '_wrapper');
//remove widths that shouldn't be there on the datatable
tableWrapper.css('width', '');
tableWrapper.find('.dataTables_scrollHead').css('width', '');
tableWrapper.find('.dataTables_scrollHeadInner').css('width', '');
tableWrapper.find('.dataTables_scrollHeadInner').find('table').css('width', '');
var tableDataContent = tableWrapper.find('.dataTables_scrollBody')[0];
var tableHasScrollBar = (tableDataContent.scrollHeight > tableDataContent.clientHeight);
//fixes header aligment issues in all major browsers
if (tableHasScrollBar)
tableWrapper.find('.dataTables_scrollHead').css('margin-right', '15px');
//fixes table data stretchyness in
Allan
Allan
Edited: nvm. Worked it out using fnAdjustColumnString. But this isn't the best solution when you have multiple tables on a page. But good enough for now.
Thanks for the great work with DataTables. It's much appreciated.
Regardless, awesome product! And thanks for this fix johnwc723.