The datatable column are not auto resizing. Here is my code
var oTable =$('#test').dataTable( {
"bJQueryUI": true,
"aaData": aDataSet,
"sPaginationType": "full_numbers",
"oTableTools": {
"aButtons": [ {"sExtends": "csv" , "sButtonText": "Save as CSV"}],
"sSwfPath": "js/jquery/copy_csv_xls.swf"
},
"bAutoWidth" : true,
"sDom": '<"H"lCf>t"H"<"F"iTp>',
"aoColumnDefs": [
{ "bVisible": true, "aTargets": [ 11 ] }
],
"aoColumns": [
{ "sTitle": "column1" },
{ "sTitle": "column1" },
{ "sTitle": "column1" },
{ "sTitle": "column1"},
{ "sTitle": "column1"},
{ "sTitle": "column1" },
{ "sTitle": "column1" },
{ "sTitle": "column1" },
{ "sTitle": "column1"},
{ "sTitle": "column1 By"},
{ "sTitle": "column1 Date"}
]
} );
oTable.fnAdjustColumnSizing();
});
I want all the columns to auto resize at least based on their header value.
The autoWidth option is used to specify whether the automatic calculation of the column width in the DataTable is enabled or not. This calculation takes a little time and may be disabled when the column widths are explicitly passed using the columns.
Set to 'fixed' for columns with equal widths. Set to 'auto' for column widths that are based on the width of the column content and the table width. The default is 'fixed'.
Select the table, then select Table Design > Resize Table.
You just do it like if it was a "normal" <table>
:
th, td {
white-space: nowrap;
}
see fidle -> http://jsfiddle.net/YrWG5/ with some extreme long header / content.
You can also use datatable's Fluid column width
feature. This will help auto-resize and add a scroll both on the X
and Y
axis should you have more columns to display
$(document).ready(function() {
var table = $('#example').DataTable( {
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false,
columnDefs: [
{ width: '20%', targets: 0 }
],
fixedColumns: true
} );
} );
Gotten from HERE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With