I want to create an HTML table using json data. The json data will change over time. When convert this json data to HTML table, the table look like this with consistent. It means the alignment of money values and the width of the table. How can I convert the json data into HTML table?
<html>
<head>
<title>Hello</title>
<style>
table{
font-family: 'Courier New', Courier, monospace;
}
td#aliCenter{
text-align:center;
}
td#aliRight{
text-align:right;
}
td#myId{
text-align:center;
font-size: 13px;
}
</style>
</head>
<body>
<table width="302.362205"> <!-- To print paper size is 80 cm (=302.362205 pixel) -->
<!-- header -->
<tr>
<td colspan="5" id="aliCenter">Moring Cafe<br>Main Road, Kandawala<br>Contact : 111-555-878</td>
</tr>
<tr>
<td colspan="5" id="myId">15/11/2018 16:14:52 SAKTHY No: 24</td>
</tr>
<tr>
<td colspan="5">
<hr>
</td>
</tr>
<tr>
<td id="aliCenter">NO</td>
<td id="aliCenter">ITEM</td>
<td id="aliCenter">QTY</td>
<td id="aliCenter">PRICE</td>
<td id="aliCenter">AMOUNT</td>
</tr>
<tr>
<td colspan="5">
<hr>
</td>
</tr>
<!-- buying items -->
<tr>
<td>1</td>
<td colspan="4">Pizza</td>
</tr>
<tr>
<td></td>
<td>PZ4545</td>
<td>2.00</td>
<td id="aliRight">150.00</td>
<td id="aliRight">300.00</td>
</tr>
<tr>
<td>2</td>
<td colspan="4">Buggers</td>
</tr>
<tr>
<td></td>
<td>BR7878</td>
<td>5.00</td>
<td id="aliRight">500.00</td>
<td id="aliRight">2500.00</td>
</tr>
<tr>
<td>3</td>
<td colspan="4">Cock</td>
</tr>
<tr>
<td></td>
<td>CC6523</td>
<td>3.00</td>
<td id="aliRight">180.00</td>
<td id="aliRight">540.00</td>
</tr>
<!-- footer -->
<tr>
<td colspan="5">
<hr>
</td>
</tr>
<tr>
<td></td>
<td colspan="3">Net Total</td>
<td id="aliRight">3340.00</td>
</tr>
<tr></tr>
<tr>
<td></td>
<td colspan="3">Cash</td>
<td id="aliRight">3500.00</td>
</tr>
<tr>
<td></td>
<td colspan="3">Balance</td>
<td id="aliRight">160.00</td>
</tr>
<tr></tr>
<tr>
<td colspan="5" id="aliCenter">-----------IMPORTANT NOTICE-----------</td>
</tr>
<tr>
<td colspan="5" id="aliCenter">In case of a price discrepancy, <br>return the bill and item within <br> 2 days to refund the difference</td>
</tr>
</table>
</body>
</html>
The json data contains main three parts. Such as header, items and footer. The header and footer is fixed, but the items's length will change over customers. The items should be circulate with the above table format, without changing the consistence.
{
"header": {
"invoice": "24",
"name": "Morning Cafe",
"address": "Main Road, Kandawala",
"contact": "111-555-878",
"date": "15/11/2018 16:14:52",
"counter": "SAKTHY"
},
"items": [{
"no": "1",
"item": "Pizza",
"code":"PZ4545",
"price": "150.00",
"qty":"2.00",
"amount":"300.00"
},
{
"no": "2",
"item": "Burger",
"code":"BR7878",
"price": "500.00",
"qty":"5.00",
"amount":"2500.00"
},
{
"no": "3",
"item": "Cock",
"code":"CC6523",
"price": "180.00",
"qty":"3.00",
"amount":"540.00"
}],
"footer": {
"total":"3340.00",
"cash":"3500.00",
"balance":"160.00",
"notice": "In case of a price discrepancy, return the bill and item within 2 days to refund the difference."
},
}