I have a datasource set out like so
[
{
"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
},
]
}
]
My issue is that I need to have a line for each person, and a column header for each city. Each object of 'Houses' will be the same for each person, but I will not know what the data is, so I can not auto set the matColumnDef.
I am finding that the below
<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>
spits out just the first iteration and doesn't continue with the nested object, example
|Full name |Denver|
|----------|------|
|Person One|True |
|Person Two|True |
Where I want
|Full name |Denver|Austin|
|-----------|------|------|
|Person One |True |True |
|Person Two |True |False |
Any help would be appreciated. I autofill the displayed columns with a foreach loop getting each of the distinct cities so I dont have an id problem, just a populating one.
Thanks.
displayedColumns?