【问题标题】:Unable to use colspan in angular material table无法在角材料表中使用 colspan
【发布时间】:2020-06-15 14:30:27
【问题描述】:

是否可以在角度材料表中使用 colspan 或者有任何其他方法可以通过任何其他方式实现 colspan?

我尝试过 [attr.colspan],但结果不正确。我添加 [attr.colspan] 后,它立即应用 colspan,但将符号移动到新的未知列。enter image description here

【问题讨论】:

标签: angular typescript html-table angular-material expand


【解决方案1】:

你可以使用[attr.colspan]这是一个例子

    <table mat-table [dataSource]="dataSource" multiTemplateDataRows>
    <ng-container matColumnDef="column">
      <th mat-header-cell *matHeaderCellDef [attr.colspan]="3">Column</th>
    </ng-container>
    </table>

【讨论】:

  • 我已经尝试过 [attr.colspan] 但没有得到正确的结果。我在帖子中添加了图片。请看一看。
  • 如果您没有正确的结果,这意味着您的代码中的其他内容会阻止您的规则被应用,您能否为您的代码创建一个堆栈闪电战?
  • 我只想要 9 个位置的“体重”选项来申请 colspan。
【解决方案2】:

您不能将colspan 与材料表一起使用。您可以设置[matColumnDef] 来定义需要显示的列。 或者 [attr.colspan] 是您可以在 mat-table 上使用的属性。虽然我自己没有试过。

垫表的列定义。定义一组可用于表格列的单元格。

Angular Material Table API

如果您真的想使用 colspan,您可以阅读 THIS 线程,其中解释了如何将 colspan 与 CdkTable 一起使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多