Maximum column width for all columns
Maximum column width for all columns
![ludwigm](https://secure.gravatar.com/avatar/0a5fa7fe0b2a9fc3692f802b5a52f362/?default=https%3A%2F%2Fvanillicon.com%2F0a5fa7fe0b2a9fc3692f802b5a52f362_200.png&rating=g&size=120)
How can I set a maximum width for all columns?
The table is generated dynamically, I can´t tell with column has too much content. Currently, a column with many characters takes up so much space that the table has to be scrolled in x-direction. If the max width is exceeded, there should be a line break.
I tried, with no visible effect:
var columnDefs = [
{
width: '50px',
targets: '_all'
}
];
This question has an accepted answers - jump to answer
Answers
Normally you can't directly - that isn't how HTML tables work. However, there are two options:
table-layout: fixed
will give you pixel perfect control over the table column widths using thetable-layout
CSS property. The downside is that the table doesn't adjust for mistakes and often content will overflow.div
(which you could do with a rendering function) and apply themax-width
to that.Allan
I chose the second option: