Table header's inline styles
Table header's inline styles
I am struggling to write CSS rules to take care of my column widths. I finally narrowed it down to my selectors getting there, but the inline properties are overriding it. Below shows my attempts.
I can resize the actual data display just fine, its the header that I'm having issues with (which is already loaded in the table within a thead item).
My initialization:
[code]
$('#example').DataTable( {
'bAutoWidth': false,
'oLanguage': {
'sEmptyTable': 'No enties found'
},
'aaData': data,
'aoColumnDefs': [
{'sWidth': '', 'aTargets': [0,1,2,3] }
],
'aoColumns': [
{'mData': 'PROPERTY_1'},
{'mData': 'PROPERTY_2'},
{'mData': 'PROPERTY_3'},
{'mData': 'PROPERTY_4'},
]
} );
[/code]
My css:
[code]
/** First th and first column of the Example page **/
#example_wrapper .dataTables_scrollHead table th:first-child,
#example td:first-child {
overflow:hidden;
width: 10%;
background-color:#000000 !important;
}
/** Second th and second column of the Example page **/
#example_wrapper table th:first-child+th {width:70% !important;}
#example_wrapper table td:first-child+td {
overflow:hidden;
width: 70%;
}
/** Third th and third column of the Example page **/
#example_wrapper .dataTables_scrollHead table th:first-child+th+th{width:10%;}
#example td:first-child+td+td {
overflow:hidden;
width: 10%;
}
/** Fourth th and fourth column of the Example page **/
#example_wrapper .dataTables_scrollHead table th:first-child+th+th+th,
#example td:first-child+td+td+td {
overflow:hidden;
width: 10%;
}
[/code]
I can resize the actual data display just fine, its the header that I'm having issues with (which is already loaded in the table within a thead item).
My initialization:
[code]
$('#example').DataTable( {
'bAutoWidth': false,
'oLanguage': {
'sEmptyTable': 'No enties found'
},
'aaData': data,
'aoColumnDefs': [
{'sWidth': '', 'aTargets': [0,1,2,3] }
],
'aoColumns': [
{'mData': 'PROPERTY_1'},
{'mData': 'PROPERTY_2'},
{'mData': 'PROPERTY_3'},
{'mData': 'PROPERTY_4'},
]
} );
[/code]
My css:
[code]
/** First th and first column of the Example page **/
#example_wrapper .dataTables_scrollHead table th:first-child,
#example td:first-child {
overflow:hidden;
width: 10%;
background-color:#000000 !important;
}
/** Second th and second column of the Example page **/
#example_wrapper table th:first-child+th {width:70% !important;}
#example_wrapper table td:first-child+td {
overflow:hidden;
width: 70%;
}
/** Third th and third column of the Example page **/
#example_wrapper .dataTables_scrollHead table th:first-child+th+th{width:10%;}
#example td:first-child+td+td {
overflow:hidden;
width: 10%;
}
/** Fourth th and fourth column of the Example page **/
#example_wrapper .dataTables_scrollHead table th:first-child+th+th+th,
#example td:first-child+td+td+td {
overflow:hidden;
width: 10%;
}
[/code]
This discussion has been closed.
Replies
Beyond that, we'd need a link to your page to see why exactly the DataTables default width handling isn't working.
Allan
In my other invocation of DataTables, they are fine when there's data in the table, its only an issue when there isn't any data, but I haven't investigated the inline styles for that one yet.
Right now I'm seeing inline styles for the header items.
[code]
...
...
...
...
[/code]
Upon clicking for a sort, they reset to what they should have been earlier, to match the columns below:
[code]
...
...
...
...
[/code]
I will try to recreate the issue in jsbin by the end of the day.
Allan
Looks like this will do the trick, thanks for the amazing package!