My data source is structured in the following way:
[
{
"UserId": "00000000-0000-0000-0000-00000000",
"FullName": "Person one",
"Houses": [
{
"State": "Colorado",
"City": "Denver",
"Code": "C_D",
"Purchased": True
},
{
"State": "Texas",
"City": "Austin",
"Code": "A_D",
"Purchased": True
},
]
},
{
"UserId": "00000000-0000-0000-0000-00000000",
"FullName": "Person Two",
"Houses": [
{
"State": "Colorado",
"City": "Denver",
"Code": "C_D",
"Purchased": True
},
{
"State": "Texas",
"City": "Austin",
"Code": "A_D",
"Purchased": False
},
]
}
]
I am facing a challenge where I need to display each person as a row and have a column header for each city. The 'Houses' objects will be consistent for each person, but the data within them varies. Since I do not know the exact data, I cannot set the matColumnDef automatically.
The code snippet below is currently outputting only the first iteration and is not proceeding with the nested object structure:
<table mat-table [dataSource]="dataSource" [trackBy]="myTrackById" fixedLayout recycleRows>
<ng-container [matColumnDef]="hb.FullName" *ngFor="let hb of HousingBlocks; let i = index">
<th mat-header-cell *matHeaderCellDef> Full Name </th>
<td mat-cell *matCellDef> {{hb.FullName}} </td>
</ng-container>
<ng-container [matColumnDef]="eventApproval.UserName" *ngFor="let hb of HousingBlocks; let i = index">
<div *ngFor="let house of hb.Houses[i];let i = index">
<th mat-header-cell *matHeaderCellDef>
{{house.City}}
</th>
<td mat-cell *matCellDef>
{{house.Purchased}}
</td>
</div>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
This results in the output similar to:
|Full name |Denver|
|----------|------|
|Person One|True |
|Person Two|True |
However, my desired format is:
|Full name |Denver|Austin|
|-----------|------|------|
|Person One |True |True |
|Person Two |True |False |
If anyone could provide assistance with populating the table correctly, it would be greatly appreciated. My loop dynamically auto-fills the displayed columns with distinct cities, eliminating any potential ID issues, but I'm struggling with the population logic.
Thank you.