title: Using Ellipsis in Angular Material Table
body: <p>By default, Angular Material Table puts content in a new line below if it overflows from the cell it is contained in. I'm trying to set it so that the overflowing text gets truncated with "..." instead. The code I have right now doesn't truncate the content and displays it in one line until it overflows out of the parent <code>&lt;div&gt;</code></p>
  
  <p>I'm using <code>&lt;table mat-table&gt;</code> instead of <code>&lt;mat-table&gt;</code> because it has columns that resize themselves based on their content as described in <a href="https://material.angular.io/components/table/overview#tables-with-code-display-flex-code-" rel="noreferrer">Angular Material Website</a>. The table I'm trying to create is responsive and resizes itself based on the size of its parent <code>&lt;div&gt;</code></p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div class="table-content"&gt;
    &lt;table mat-table [dataSource]="dataSource" class="table-container"&gt;
      &lt;ng-container [matColumnDef]="item" *ngFor="let item of displayedColumns"&gt;
        &lt;th mat-header-cell *matHeaderCellDef&gt;{{item}} &lt;/th&gt;
        &lt;td mat-cell *matCellDef="let element"&gt;
          &lt;div class="table-data-content"&gt;
            &lt;span&gt;{{element[item]}}&lt;/span&gt;
          &lt;/div&gt;
        &lt;/td&gt;
      &lt;/ng-container&gt;
      &lt;tr mat-header-row *matHeaderRowDef="displayedColumns;"&gt;&lt;/tr&gt;
      &lt;tr mat-row *matRowDef="let row; columns: displayedColumns;"&gt;&lt;/tr&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>CSS:</p>
  
  <pre><code>.table-container {
    position: absolute;
    width: 100%;
    height: 100%;
  }
  .table-data-content {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  </code></pre>
  
  <p>Sample data used in Angular Component:</p>
  
  <pre><code>  dataSource = [
      { Name: "Some file name that is very long", Date: '08/30/2017', Uploader: 'Some uploader name that is very long'},
      { Name: "Some file name that is very long", Date: '08/30/2017', Uploader: 'Some uploader name that is very long'}
    ];
  
    displayedColumns = ['Name', 'Date', 'Uploader'];
  </code></pre>
  
  <p>What could I fix to appropriately use ellipsis in my table?</p>
  
  <p><strong>Update:</strong>
  The ellipsis works if I add the following css, which I am still not sure why.</p>
  
  <pre><code>td {
  max-width: 0px;
  }
  </code></pre>
  
  <p>However, this approach disrupts the way Angular Material Table efficiently assigns the width of each column based on the length of the content so that the content gets truncated when the other column still has a lot of empty space left. Is there better solution to this?</p>