I have issues displaying data from one of the JSON object it get from my client. I see only the header data. I am not clear what am i missing.
I checked the JSON file sent by the client, it is good.
TS File Code:
import { Component, OnInit, Input } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';
@Component({
selector: 'app-list-student',
templateUrl: './list-student.component.html',
styleUrls: ['./list-student.component.css']
})
export class ListStudentComponent implements OnInit {
studentData: any;
headerColumns: string[] = ["FIRST_NAME", "LAST_NAME", "DOB_DATE"];
dataSource = new MatTableDataSource([]);
summaryTableConfig = [
{
'headerValue' : 'First Name',
'columnValue' : 'FIRST_NAME',
},
{
'headerValue' : 'Last Name',
'columnValue' : 'LAST_NAME',
},
{
'headerValue' : 'DOB',
'columnValue' : 'DOB_DATE',
}
];
constructor() { }
ngOnInit() {
this.studentData = {"header": {"columnsMap": {"DOB_DATE": "12/12/1942","FIRST_NAME": "JOHN","LAST_NAME": "DOE"}}};
this.dataSource = new MatTableDataSource;
this.dataSource.data = this.studentData;
}
}
HTML Code
<mat-table [dataSource]="dataSource">
<ng-container *ngFor="let data of summaryTableConfig" [matColumnDef]="data.columnValue">
<mat-header-cell *matHeaderCellDef>
<span>{{ data.headerValue }}</span>
</mat-header-cell>
<mat-cell *matCellDef="let element">
<span>{{element["columnsMap"][data.columnValue]}}</span>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="headerColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: headerColumns;"></mat-row>
</mat-table>