I'm trying to populate a multidimensional html table with data from a JSON. The idea is that the first row is with the dates and the next ones start with with the name of the value and for the value for the date in the first row. Just like and x-y kind of table.
This is an example of my data:
{"dataval": [
{
"date":"2014-01-01 00:00:00",
"value":25776510,
"name":"ISLA--T"
},
{
"date":"2014-01-01 00:00:00",
"value":789,
"name":"ISLA--Total"
},
{
"date":"2014-01-01 00:00:00",
"value":0,
"name":"SLA-TSis"
},
{
"date":"2014-01-01 00:00:00",
"value":0,
"name":"PServSLA-CdS"
}
]}
This is what I want to achieve:
<table style="width:100%">
<tr>
<th></th>
<th>date</th>
<th>date</th>
</tr>
<tr>
<th>value name</th>
<td>value</td>
<td>value</td>
</tr>
<tr>
<th>value name</th>
<td>value</td>
<td>value</td>
</tr>
</table>
I've tried many different approaches, so I won't copy here all the different solutions I've tried, I rather explain them a bit, as I don't to correct my code as such, although I will publish my last approach if it's needed.
I've tried iterating through the json in frontend, making the table with jQuery but I just couldn't make the values match with their corresponding name and date.
I've tried formatting the json in backend and then looping through it in frontend, but again the values wouldn't match. If I didn't have a value for one value-name the values would go to another value-name, etc.
Thanks in advanced!