I have a mat-table I want to auto fit column width, anyone will be as long as the longest column content.
<mat-table #table [dataSource]="dataSource">
<ng-container matColumnDef="email">
<mat-header-cell *matHeaderCellDef class="myHeader"> No. </mat-header-cell>
<mat-cell *matCellDef="let element" class="myCell"> {{element.email}} </mat-cell>
</ng-container>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef class="myHeader"> Name </mat-header-cell>
<mat-cell *matCellDef="let element" class="myCell"> {{element.name}} </mat-cell>
</ng-container>
</mat-table>
Data example:
const DATA: Data[] = [
{email: 'mail1@mail.com', name: 'Long name for this person'},
{email: 'mail2@mail.com': 'name2',
{email: 'longmailaddres@longmailaddress.com: 'name3'}
];
So, width cells will be enough for "longmailaddress@longmailaddres.com" and for "Long name for this person".
My choices doesnt work, I tried with FxFlexFill and fxFlex unsucced this is my css unsucced option.
.myHeader, .myCell{
flex: 0 0 100px;
white-space: nowrap;
}
Can somebody help me?