【问题标题】:Mat-table columns collapsing on each other垫表列相互折叠
【发布时间】:2020-04-09 11:46:41
【问题描述】:

我有一个垫表来显示价格和持续时间之间的相关性,可以在其中编辑字段。当前的 HTML 是这样的:

  <table mat-table [dataSource]="item.durations_array">
    <ng-container matColumnDef="duration">
      <mat-header-cell *matHeaderCellDef> Duration </mat-header-cell>
      <mat-cell *matCellDef="let element; index as i">
        <mat-form-field floatLabel="never">
          <input
            matInput
            placeholder="Duration"
            disabled="{{ !isEditing }}"
            [value]="item.durations_array[i]"
            [(ngModel)]="item.durations_array[i]"
          />
        </mat-form-field>
      </mat-cell>
    </ng-container>

    <ng-container matColumnDef="price">
      <mat-header-cell *matHeaderCellDef> Price </mat-header-cell>
      <mat-cell *matCellDef="let element; index as i">
        <mat-form-field floatLabel="never">
          <input
            matInput
            placeholder="Price"
            disabled="{{ !isEditing }}"
            [value]="item.prices_array[i]"
            [(ngModel)]="item.prices_array[i]"
          />
        </mat-form-field>
      </mat-cell>
    </ng-container>
    <tr mat-header-row *matHeaderRowDef="['duration', 'price']"></tr>
    <tr mat-row *matRowDef="let element; index as i; columns: ['duration', 'price']"></tr>
  </table>

问题是这些列像这样堆叠在一起,当我希望它们并排时:

我尝试将display: block 包含到表格和单元格中,但没有效果。我可以通过禁用桌面上的 flexbox 在检查器中获得一些结果,但我认为 display:block 会这样做吗?

【问题讨论】:

  • 你可以试试“display:block”而不是“style:block”吗?
  • 抱歉,这里有错字。我使用了 display:block 但在这里写错了。已在原帖中更正
  • 为什么不使用&lt;th mat-header-cell *matHeaderCellDef&gt;&lt;td mat-cell *matCellDef="let element"&gt;? (您直接使用&lt;mat-header-cell&gt;&lt;mat-cell&gt;
  • 这就是问题所在!想知道我从哪里得到了忘记元素中的 thtd 的想法

标签: html angular flexbox angular-material


【解决方案1】:

由 Eliseo 的评论修复,我忘记了标题和单元格定义。这是工作代码:

<table mat-table [dataSource]="item.durations_array">
    <ng-container matColumnDef="duration">
      <th mat-header-cell *matHeaderCellDef>Duration</th>
      <td mat-cell *matCellDef="let element; index as i">
        <mat-form-field floatLabel="never">
          <input
            matInput
            placeholder="Duration"
            disabled="{{ !isEditing }}"
            [value]="item.durations_array[i]"
            [(ngModel)]="item.durations_array[i]"
          />
        </mat-form-field>
      </td>
    </ng-container>

    <ng-container matColumnDef="price">
      <th mat-header-cell *matHeaderCellDef>Price</th>
      <td mat-cell *matCellDef="let element; index as i">
        <mat-form-field floatLabel="never">
          <input
            matInput
            placeholder="Price"
            disabled="{{ !isEditing }}"
            [value]="item.prices_array[i]"
            [(ngModel)]="item.prices_array[i]"
          />
        </mat-form-field>
      </td>
    </ng-container>
    <tr mat-header-row *matHeaderRowDef="['duration', 'price']"></tr>
    <tr mat-row *matRowDef="let element; index as i; columns: ['duration', 'price']"></tr>
  </table>

【讨论】:

    猜你喜欢
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    相关资源
    最近更新 更多