Issue
I want to create the following dynamic column table using Angular.js.
According to my requirement, column sets such as fruit, vegetables can change dynamically according to the data sets. I want to load data from a JSON file. ex:
[
{
"clusterID":"1",
"storeCode": "S2HK",
"storeName": "store 1",
"Vegetables":
{
"Ordered":"272",
"Delivery":"250",
"FR":"70%",
"Gap":"22"
},
"Fruit":
{
"Ordered":"300",
"Delivery":"250",
"FR":"60%",
"Gap":"50"
}
},
{
"clusterID":"1",
"storeCode": "SCCC",
"storeName": "store 2",
"Vegetables":
{
"Ordered":"500",
"Delivery":"500",
"FR":"100%",
"Gap":"0"
},
"Fruit":
{
"Ordered":"750",
"Delivery":"700",
"FR":"90%",
"Gap":"50"
}
}
]
I tried many ways but was unable to create a dynamic table. How can I create this type of table?
Solution
You need to make the table structure like this:
<table border="1" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th rowspan="2">Store</th>
<th rowspan="2">Store Name</th>
<th colspan="4">Vegetables</th>
<th colspan="4">Fruit</th>
</tr>
<tr>
<th>Ordered</th>
<th>Delivery</th>
<th>FR</th>
<th>Gap</th>
<th>Ordered</th>
<th>Delivery</th>
<th>FR</th>
<th>Gap</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of items">
<td>item.storeCode</td>
<td>item.storeName</td>
<td>item.Vegetables.Ordered</td>
<td>item.Vegetables.Delivery</td>
<td>item.Vegetables.FR</td>
<td>item.Vegetables.Gap</td>
<td>item.Fruit.Ordered</td>
<td>item.Fruit.Delivery</td>
<td>item.Fruit.FR</td>
<td>item.Fruit.Gap</td>
</tr>
</tbody>
You can see the working jsBin here
Answered By - Rohit Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.