How can I specify a min-width
for a column in DataTables?
I can't use a class with className
because the width is variable. The width
option isn't sufficient. There doesn't appear to be a style
option.
The best way to use min-width is to define a width value as a percentage and use an absolute value for the min-width property otherwise using a percentage value for for both min-width and width will not produce the expected result.
I would still recommend to use a class name or multiple class names and columns.className
option to keep CSS rules where they belong - in CSS files.
However if you want to assign min-width
value at run-time, you can use createdRow
option to define a callback for whenever a TR
element is created for the table's body.
var table = $('#example').DataTable({
'createdRow': function(row, data, dataIndex){
$('td:eq(3)', row).css('min-width', '200px');
}
});
See this example for code and demonstration.
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