columndefs targes css selector
columndefs targes css selector

I am trying to set column widths by using css selector:
columns: [{ title: 'value1', data:'value1' , name:'value1', visible: false, searchable: false, className: 'no-searchbuilder no-colvis-control'},
{ title: 'value2', data:'value2' , name:'value2', visible: true, searchable: true, className: 'no-searchbuilder float-number'},
{ title: 'value3', data:'value3' , name:'value3', visible: true, searchable: true, className: 'float-number'}],
..
columnDefs: [{ width: 70, targets: '.float-number' }]
..
and I also tried to define the class in the php with the table defintion:
<th class="float-number">Jordan Followup</th>
but it doesn't seem to be working.
I am trying to get away from having to specify the column #'s as if I add any new columns, then I have to update multpile places that utilize columndefs with a target for specific columns.
This question has an accepted answers - jump to answer
Answers
For a class name target to work, you need to have it in your HTML. It doesn't work for classes which are assigned by
columns
.That should work, although you note that it doesn't. Perhaps you can link to a test case?
Here is an example of that working: https://live.datatables.net/qijejace/1/edit .
Allan
Thank you for the example, I was able to recheck and it worked (not sure what I changed, lol). Question, should I consider placing all the column class assignments in the HTML (to avoid other issues)?
No, because that only applies to the header cells. DataTables doesn't read the header classes and then apply other to the body cells for the columns.
Allan
Thank you!