I am facing a unique scenario where the backend data I receive is organized in a column-oriented format. Here is an example of how the data structure looks:
[
{ columnName: "ID", cells: [1, 2, 3, 4, 5] },
{ columnName: "Name", cells: ["a", "b", "c", "d", "e"] }
]
Currently, I have configured my mat-table in the following way:
<table mat-table [dataSource]="data" class="mat-elevation-z8">
<ng-container [matColumnDef]="column" *ngFor="let column of displayedColumns">
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
<td mat-cell *matCellDef="let element">{{element | json}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
This setup results in the current display:
https://i.sstatic.net/0tVon.png
However, I am aiming for a table layout like this:
|------|------|
| ID | NAME |
|------|------|
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
| 5 | e |
Is there a way to adjust the matRowDef so that it interprets the cells property as rows? Ideally, I would prefer making this adjustment within the mat-table without altering my data and having to convert it back later on.