1

I have data saved in SQL in the form below : enter image description hereOnce I retrieve the data in array format in react such as :

const tbldata = [[cat,dog,bird,cow],[victoria,vancouver,calgary,montreal],[apple,mango,bananas,grapes],[car,plane,truck,train]];

const headers = [A,B,C,D];

How do I display the data in table form in React.js? Like this below?

A B C D
cat dog bird cow
victoria vancouver calgary montreal
apple mango bananas grapes
car plane truck train

I tried using material table because I'm not sure how to use the other table. This is what I tried :

<MaterialTable
    columns = headers     
    data = tbldata
\>

Which is not what I'm looking for. I don't know how to map the array data in a table format.

2
  • 1
    <MaterialTable columns=headers data=tblData /> ? Commented Nov 17, 2022 at 22:20
  • 1
    Have you looked at the documentation or any tutorials? Commented Nov 17, 2022 at 22:21

1 Answer 1

1

I think this will help you.

 class App extends Component {
      render() {
        return (
            <MaterialTable
              columns={[
                { title: 'A', field: 'A' },
                { title: 'B', field: 'B' },
                { title: 'C', field: 'B' },
                { title: 'D', field: 'D' }
              ]}
              data={tbldata.map((item)=> ({A: item[0], B: item[1], C: item[2]}))}
              title="Title"
            />
        )
      }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.