The table should display the data as defined in displayedColumns. The group column has a rowspan of 2 and the row column displays the [rows.title] which is the row header and displayed for every iteration. The rest of the columns displays the data with regards to the row.title and col If anyone can help out with the table html .
//column order
let displayedColumns = ['group','row','0','1','2'];
// tabledata object
let tableData = [{
salesHist: [1, 2, 3, 4],
sales: [1, 2, 3, 4],
forecastHist: [1, 2, 3, 4],
forecast: [1, 2, 3, 4],
group: "000",
recordCount: "1234",
rows: [{
key: "forecast",
title: "Forecast"
}, {
key: "sales",
title: "Sales"
}, {
key: "salesHist",
title: "Sales History"
}]
}];
//table html
<table
mat-table
matSort
[dataSource]="table"
multiTemplateDataRows
class="w-100"
>
<ng-container *ngFor="let group of table" matColumnDef="group">
<th mat-header-cell *matHeaderCellDef mat-sort-header>
{{ group }}
</th>
<td mat-cell *matCellDef="let row" [attr.rowspan]="4">
{{ group }}
</td>
</ng-container>
<ng-container matColumnDef="row">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let row; let i = index">
<span *ngFor="let rowTitle of row.rows">{{ rowTitle.title }}</span>
</td>
</ng-container>
<ng-container
*ngFor="let periodCol of monthsPeriod"
matColumnDef="{{ periodCol.col }}"
>
<th mat-header-cell *matHeaderCellDef>
{{ getTitle(periodCol) }}
</th>
<td class="sim-row-cell" mat-cell *matCellDef="let rowTitle">
{{ getValue(rowTitle, periodCol) }}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let element; columns: displayedColumns"></tr>
</table>