Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material Table Cell Data wrapping

I m using Angular material for displaying table data. This is just partial code. The table is embedded in material card. The data in the table cell gets messy when the length of the field is more. i have attached the screenshot for the same

<mat-card-content fxLayout="column" fxLayoutAlign="space-between" fxFlex>
  <h4>Incidents</h4>
  <mat-table #table [dataSource]="dataSource" matSort class="mat-elevation-z8">
    <ng-container matColumnDef="IncidentId">
      <th mat-header-cell fxFlex *matHeaderCellDef mat-sort-header>IncidentId</th>
      <td mat-cell fxFlex *matCellDef="let element">{{ element.IncidentId }}</td>
    </ng-container>
    ...

Here's how it looks:

enter image description here

I have used word wrap but it didn't help

The same code appears in IE in the below format

[enter image description here2

like image 996
NewBee Avatar asked Oct 11 '18 20:10

NewBee


2 Answers

This should fix the wrap issue with the Angular material table:

put this style in your component's style file (.css or scss or any other style extension)

 td , th {
    white-space: normal;
    word-wrap: break-word;
    max-width: 200px;
}

You can adjust the max-width to your taste. It actually worked for me in my case.

like image 159
keemsisi Avatar answered Sep 23 '22 06:09

keemsisi


As far as I remember

fxLayout="column" fxLayoutAlign="space-between" fxFlex

fxFlex is deprecated and fxLayout should be fxLayout="column wrap"

I gues you have overflow: hidden


Can you apply these styles on on that column

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
like image 21
Vivek Kumar Avatar answered Sep 23 '22 06:09

Vivek Kumar