To my knowledge Angular Material does not cater for nested rows.
I solved this issue by maintaining a "flat" table and changing the style of sub/nested rows to appear as such. To do this, the data needs to be ordered so that each row's sub rows are placed after it.
Ordering ex.
- Row 1
- Row 1 Nested Row 1
- Row 1 Nested Row 2
- Row 2
- Row 2 Nested Row 1
- etc.
Once the data is ordered, you need to identify and apply your class to the nested rows.
CSS - Nested row class example:
.example-table {
width: 100%;
.cdk-column-a {
}
..
.sub-level-row {
td {
font-size: 11px;
opacity: 0.85;
border-bottom: 1px solid;
}
}
}
HTML - Apply class using [ngClass] to nested rows:
<tr mat-row [ngClass]="{'sub-level-row': isSubLevelRow(rowData)}"
*matRowDef="let rowData; columns: tableColumns"></tr>
TS - Determine if row is nested:
isSubLevelRow(rowData) {
// use your data to determine if nested row
return rowData.parentId !== null;
}
Result:
Apply padding, margins, colors etc. for more nested look.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…