0

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"
        ]
    ]
}

2 Answers 2

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you so much
1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.