我有一个有角度的材料mat-table
我使用 CSS 样式来替代行颜色。这是 CSS 样式:
.mat-row:nth-child(even){
background-color: #e4f0ec;
}
.mat-row:nth-child(odd){
background-color:#ffffff;
}
当我的 mat-table 没有定义的子行时,这有效。当我添加另一个ng-container
这是用“expandedDetail”指定的,这不再起作用。所有行都是白色的,但展开的子行是彩色的。
我按照material.angular.io 中的示例进行操作
我看到其他行样式示例,但它们使用 tr 标签。在示例和我的代码中,我使用了ng-container
每列的 , th 和 td 标签。
任何帮助表示赞赏。
我将项目添加到 stackblitz
https://stackblitz.com/edit/angular-4bcxtv https://stackblitz.com/edit/angular-4bcxtv
这是我使用的 HTML 代码
<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>
<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="columnsToDisplay"></tr>
<tr mat-row *matRowDef="let element; columns: columnsToDisplay;"
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>
该死的-这花了我太长时间才找到,更糟糕的是..我不知道它为什么有效..
.mat-row:nth-child(2n+1){
background-color: #e4f0ec;
}
.mat-row:not(:nth-child(4n+1)){
background-color:#ffffff;
}
我希望我能帮助你:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)