Dynamic number of columns - make width equal
Dynamic number of columns - make width equal
mikepoole
Posts: 11Questions: 5Answers: 0
I have a table that is dynamically created. Is there a way to make all the column widths equal?
Would I have to get the number ofcolumns then convert this into a variable containing the percentage and then apply to columnDefs width?
This discussion has been closed.
Answers
Hi @mikepoole ,
You could do it that way, or you could just set the header afterwards, which will force the rest of the table to follow, so something like this from the example here:
Cheers,
Colin
Thanks Colin
I'm not sure I get what you mean though - so I still need to calculate the number of columns I have built and then apply that percentage to the headers?
How would I apply it to ALL headers?
Would
$('#example thead th:eq').css( 'width', tablePercent + '%' );
work (where tablePercent is my calculated value?Hi @mikepoole ,
Yep, so you could calculate the percentage as you said, then set all widths in a single jQuery statement. i.e.:
Cheers,
Colin