In my app I have a bunch of different material tables. I want to find some way to automatically set column width.
I know, I can set this directly in CSS like this and I try this
.mat-column-position {
flex: 0 0 10%;
}
.mat-column-name {
flex: 0 0 25%;
}
.mat-column-weight {
flex: 0 0 25%;
}
.mat-column-symbol {
flex: 0 0 25%;
}
But in this way, I need to manually set the width for every table.
I also try dynamically set CSS with SCSS
@mixin mat-table-columns($columns)
{
.mat-column-
{
@each $colName, $props in $columns {
$width: map-get($props, 'width');
&#{$colName}
{
flex: $width;
min-width: $width;
@if map-has-key($props, 'color')
{
color: map-get($props, 'color');
}
}
}
}
}
@include mat-table-columns((
orderid: (width: 6rem, color: gray),
date: (width: 9rem),
items: (width: 20rem)
));
But in all of these ideas, I need to manually set the width.
I try to find, is there any way to automatically set the width relative to the string with the longest length
| abc | abcdefg | abcdefgh |
| abcde | abc | abc |
| ab | abcdef | abc |
Here is stackblitz for example. Thnx