I am trying to iterate through an array of objects in reactjs but facing issue. The array basically consists of objects where each object is a row in a table.
Example -
A table like this
| A | B | C |
| 1 | 2 | 3 |
| 4 | 5 | 6 |
would be represented using the following array
[
{"A": 1, "B": 2, "C": 3},
{"A": 4, "B": 5, "C": 6}
]
I am trying to loop through the values using the following syntax -
this.state.data.map(item =>
Object.entries(item).map(([key, value]) =>
<Column field={key} header={key}>{value}</Column>
))
But this gives me the desired table concatenated multiple times. I know there's some issue with the looping but not getting exactly where the difficulty is.
Similar case in python would look like -
for item in array:
for key, value in item.items():
# create a row
You should consider realigning your way of rendering.
I guess first to get the
thead
header of your table which can be done byThen after that is the
tbody
which can be done byReference: https://reactjs.org/docs/thinking-in-react.html
EDIT: You can replace my example of
thead
,tbody
,tr
,td
withGrid
,TableHead
,TableBody
,Row
,Column
whichever library components of yours but you get the idea.