【发布时间】:2021-12-29 20:44:21
【问题描述】:
我正在尝试在 ngfor 之后再添加 2 个列(状态和按钮)。但是,它似乎会破坏整个结构(如图所示)
I am modifying code from material.angular.io
我还在columnsToDisplays 中添加了另外 2 行,因此它将显示额外的列。
任何关于修复它的建议将不胜感激!
<table mat-table
[dataSource]="dataSource" multiTemplateDataRows
class="mat-elevation-z8">
<ng-container matColumnDef="{{column}}" *ngFor="let column of columnsToDisplay">
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
<td mat-cell *matCellDef="let element"> {{element[column]}} </td>
</ng-container>
<!-- Expanded Content Column - The detail row is made up of this one column that spans across all columns -->
<ng-container matColumnDef="expandedDetail">
<td mat-cell *matCellDef="let element" [attr.colspan]="columnsToDisplay.length">
<div class="example-element-detail"
[@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
<div class="example-element-diagram">
<div class="example-element-position"> {{element.position}} </div>
<div class="example-element-symbol"> {{element.symbol}} </div>
<div class="example-element-name"> {{element.name}} </div>
<div class="example-element-weight"> {{element.weight}} </div>
</div>
<ng-container matColumnDef="expandedDetail">
<mat-header-cell *matHeaderCellDef> Action</mat-header-cell>
<mat-cell *matCellDef="let element">
<button mat-raised-button > Accept</button>
<button mat-raised-button > Reject</button>
</mat-cell>
</ngcontainer>
<div class="example-element-description">
{{element.description}}
<span class="example-element-description-attribution"> -- Wikipedia </span>
</div>
</div>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columnsToDisplays"></tr>
<tr mat-row *matRowDef="let element; columns: columnsToDisplays;"
class="example-element-row"
[class.example-expanded-row]="expandedElement === element"
(click)="expandedElement = expandedElement === element ? null : element">
</tr>
<tr mat-row *matRowDef="let row; columns: ['expandedDetail']" class="example-detail-row"></tr>
</table>
【问题讨论】:
-
我忘记添加状态栏了,但是按钮部分是一样的。
-
您要添加列还是行?在标题中是“行”,在描述中是“列”