Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specifiy a column min-width?

Tags:

datatables

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.

like image 801
mpen Avatar asked Nov 10 '16 19:11

mpen


People also ask

How do you use minimum width?

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.


1 Answers

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.

like image 64
Gyrocode.com Avatar answered Sep 30 '22 07:09

Gyrocode.com