Reputation: 43
How to create Dynamic Html Table with Column and row ? Below is the JSON data and I want to create HTML table using this data :
{
"columnNames": [
"Applicant ID(id|Optional)",
"Roll No",
"Applicant Name",
"Password",
"CA ID",
"Shift Name",
"Shift Date",
"Start Time",
"End Time"
],
"rows": [
[
"122",
"18",
"Amit",
"12345",
"42",
"testShift2",
"2019-12-31",
"13:00",
"16:00"
]
]
}
Upvotes: 0
Views: 345
Reputation: 1212
Try bellow code will work fine.
<table>
<tr>
<th *ngFor=" let header of data?.columnNames">{{header}}</th>
</tr>
<tbody>
<tr *ngFor=" let row of data?.rows">
<td *ngFor=" let item of row">{{item}}</td>
</tr>
</tbody>
</table>
Upvotes: 1
Reputation: 22203
Suppose your json is stored in data
,
Try like this:
<table>
<tr>
<th *ngFor="let item of data.columnNames">{{item}}</th>
</tr>
<tr *ngFor="let rowData of data.rows">
<td *ngFor="let el of rowData">{{el}}</td>
</tr>
</table>
Upvotes: 2