Table header and field problem from JSON

UI Components for React
Post Reply
kilokalas
Posts: 1
Joined: 03 Aug 2022, 07:37

03 Aug 2022, 07:48

I have a JSON file I need to put into a table. I have inserted the table body but the weird part is the title repeats more times instead of being one time.

0: {dogId: 100, dogBreed: 'Beagles' , dogCountry: 'USA'}

1: {dogId:200, dogBreed: 'GermanSheperd', dogCountry: 'Germany'}

2: {dogId:300, dogBreed:'Dalmation', dogCountry:'Russia'}

...it goes on until 100 index. My goal is to have dogId , dogBreed and dogCountry as headers/title for the table and fill their respective values from the JSON.

{dogData.map ((col,index)=>(

<Column
field = {Object.values(Object.keys(col)[index]}
header = {Object.keys(col)[index]}
></Column>

))}



But my code shows , using map function, I get the 3 headers and their values as row, but also another 97 headers with no values in the table. Is there any way to remove the other 97 undefined headers and empty fields from displaying in my table.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

05 Aug 2022, 14:29

I would not do what you are doing. Just follow the PrimeReact Showcase examples of how to build a table from JSON rows.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests