This is my data table.
I can't seem to control the width of any of the columns:
$(document).ready(function() {
$('#example').DataTable( {
"ajax": 'ajax/data/arrays.txt'
} );
I have tried various methods here:
$('#example').dataTable( {
"autoWidth": false
} );
And here:
$('#example').dataTable( {
"columnDefs": [
{ "width": "20%", "targets": 0 }
]
} );
Without success.Can anyone advise me on how I can manually control the width of some individual columns? I am hoping it can be done using existing method in datatables.
Note: I will post a fiddle if I get a chance. fiddle here - It is not exactly the same, but if my understanding is correct, I should be abloe to control the column width here:
var table = $('#example').DataTable();
My experience is that columns.width
mostly is suitable for relative intents, i.e "I want this column to be relatively larger". There is a lot that can inflict on each column width, and even if you carefully target each column with an exact percentage that add up to 100 you end up frustrated.
If you want exact, precise column width definitions there is no way around hardcoded CSS :
table.dataTable th:nth-child(1) {
width: 20px;
max-width: 20px;
word-break: break-all;
white-space: pre-line;
}
table.dataTable td:nth-child(1) {
width: 20px;
max-width: 20px;
word-break: break-all;
white-space: pre-line;
}
http://jsfiddle.net/6eLg0n9z/
something like
#table-foo td:nth-child(3),
#table-foo td:nth-child(4) {
width: 5%;
max-width: 5%;
}
worked for me, you specify columns by rules separated by comma
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