In this post, we will see how to resolve Trying to map response in table but not getting expected output
As I am trying to add rowspan attribute in table cell it only showing two rows only and third name showing in other column as well getting problem in mapping children name. the expected output will be 2 rowspan for first id of object and 1 rowspan for second id of object and 2 rowspan for second id of object and same for user_name. Expected table attached below
I couldn’t comment so I am adding an answer here with a potential solution.
So I found that you have a typo of sorts, you didn’t write your second map function correctly, this is how it should be:
I hope this helps, in case it’s not helpful, please provide a screenshot or something of what you’re seeing and maybe explain with a sketch what you want to do as well, I’ll do my best to help you out!
According to your sketch I think this should work, the trick is to lay out the first element of the children array first with the other data, and then use slice to remove the first element and loop through the rest to add them to the table.
You should also make sure that the data you received does have children, for example by checking the length before starting to display your data, just as a safety measure.
This is how it looks:
If you have better answer, please add a comment about this, thank you!