0

I have the Angular Material Table. It doesn't work properly. It' doesn't take the whole width. How could I force it to take the entire width?

<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
  <!-- Position Column -->
  <ng-container matColumnDef="position">
    <th mat-header-cell *matHeaderCellDef>No.</th>
    <td mat-cell *matCellDef="let element">{{ element.position }}</td>
  </ng-container>

  <!-- Name Column -->
  <ng-container matColumnDef="name">
    <th mat-header-cell *matHeaderCellDef>Name</th>
    <td mat-cell *matCellDef="let element">{{ element.name }}</td>
  </ng-container>

  <!-- Weight Column -->
  <ng-container matColumnDef="weight">
    <th mat-header-cell *matHeaderCellDef>Weight</th>
    <td mat-cell *matCellDef="let element">{{ element.weight }}</td>
  </ng-container>

  <!-- Symbol Column -->
  <ng-container matColumnDef="symbol">
    <th mat-header-cell *matHeaderCellDef>Symbol</th>
    <td mat-cell *matCellDef="let element">{{ element.symbol }}</td>
  </ng-container>

  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>

CSS:

table {
  width: 100%;
}

2
  • Just for reference you can take a look at this post- stackoverflow.com/questions/52746555/… Commented Sep 6, 2021 at 7:24
  • Thank you, but it's not my problem actually. My problem is that the entire table doesn't take all width, not just columns Commented Sep 6, 2021 at 7:25

2 Answers 2

2

As you have it, it is as specified in the Table | Angular Material documentation so that it takes the entire width. You might have a parent div or container with a smaller width property and therefore your table is not taking all the space. If you don't want to force it with the important! tag, try to investigate that in your HTML code.

You can also try to use the flex version for the table Tables with display: flex | Angular Material nevertheless it is not compatible with some native features for the table component.

Sign up to request clarification or add additional context in comments.

Comments

0

(should be a comment will delete later)

did you try:

table { width: 100%!important; } ?

1 Comment

yes, but it's not a good practice with !important. I'm trying something different

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.