【问题标题】:mat-paginator width is not aligned with mat-tablemat-paginator 宽度与 mat-table 不对齐
【发布时间】:2020-07-15 01:35:18
【问题描述】:

我正在为我的桌子使用有棱角的材料。在我的代码中,有时数据会超过监视器大小,因此会出现水平滚动条。在这种情况下,我的分页器未与如下表对齐

我想以相同的宽度对齐 mat-table 和 mat-paginator。

下面是我的html

<div class="mat-elevation-z8">
  <table mat-table [dataSource]="dataSource">

    <!-- 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>
  
    <mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
  </div>

下面是我的 CSS

table {
    width: 100%;
  }

请帮我解决这个问题

【问题讨论】:

  • overflow:auto样式的容器包裹表格

标签: html css angular angular-material material-table


【解决方案1】:

这是我的解决方案&lt;div style="display: inline-table;"

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

【讨论】:

  • 嗨 moio99 m 2 63 感谢您尝试回答这个问题。您能否使用正确的代码格式稍微整理一下您的答案,或许还有一个完整的示例?
  • 对于建议的案例,我必须这样说:
  • 我已将您的评论移至您的答案中。一旦/如果它被批准为编辑,请随时进行您认为必要的任何更改
  • 编号 {{element.position}}
猜你喜欢
  • 1970-01-01
  • 2020-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-23
  • 1970-01-01
  • 2019-09-25
  • 2019-07-08
相关资源
最近更新 更多