I have started with reacr-redux. in that I have got some json data to populate as table structure. for that I have data like this
[
{
"year": 2016,
"mix": [{
"name": "A",
"volume": 0.55,
},
{
"name": "B",
"volume": 0.2,
},
{
"name": "C",
"volume": 0.0,
},
{
"name": "D",
"volume": 0.0,
}],
},
{
"year": 2017,
"mix": [{
"name": "A",
"volume": 0.55,
},
{
"name": "B",
"volume": 0.2,
},
{
"name": "C",
"volume": 0.0,
},
{
"name": "D",
"volume": 0.0,
}],
},
{
"year": 2018,
"mix": [{
"name": "A",
"volume": 0.55,
},
{
"name": "B",
"volume": 0.2,
},
{
"name": "C",
"volume": 0.0,
},
{
"name": "D",
"volume": 0.0,
}],
},
{
"year": 2015,
"mix" :[{
"name": "A",
"volume": 0.55,
},
{
"name": "B",
"volume": 0.2,
},
{
"name": "C",
"volume": 0.0,
},
{
"name": "D",
"volume": 0.0,
}]
},
{
"year": 2019,
"mix": [
{
"name": "A",
"volume": 0.55,
},
{
"name": "B",
"volume": 0.2,
},
{
"name": "C",
"volume": 0.0,
},
{
"name": "D",
"volume": 0.0,
}
],
}
]
and I want my table structure like this. basically it extracts year and of that year all the mix. so final table structure should look like this
2015 2016 2017 2018
A 0.55 0.55 0.55 0.55
B 0.2 0.2 0.2 0.2
C 0 0 0 0
D 0 0 0 0
for that I have written code like this
<table className="table table-bordered">
<thead>
<tr>
<th></th>
{this.props.allYear.map((data) =>(
<th>{data.year.toString().substr(0,4)}</th>
))}
</tr>
</thead>
<tbody>
{this.props.allYear.map((data) =>(
data.mix.map((Data1) => (
<tr>
{Data1.name}
</tr>
))
))}
<td></td>
{this.props.allYear.map((data) =>(
<td>
{data.mix.map((Data1) => {
return(
<tr>
{Data1.volume}
</tr>
)
})}
</td>
))}
</tbody>
</table>
but my all the data went 1 tr down because of the tr I have written so table looks like this
2015 2016 2017 2018
A
B
C
D
0.55 0.55 0.55 0.55
0.2 0.2 0.2 0.2
0 0 0 0
0 0 0 0.
Please let me know how to fix this