1

Material ui table accept data in this format.

 rows: [
      createData(1, "dashboard", "details"),
      createData(2, "product", "product details"),
    ].sort((a, b) => (a.id < b.id ? -1 : 1))

And the response from API that I store in state is like

rows: Array(2)
 0: {id: 1, category_name: "dashboard", category_details: "details"}
 1: {id: 2, category_name: "product", category_details: "product details"}
 length: 2
__proto__: Array(0)

So how to assign the response from json array to material ui table in react?

1 Answer 1

3

Do something like below

 const dataRows = [];
 this.state.rows.forEach((item, i) => {
    dataRows.push(createData(item.id, item.category_name, item.category_details));
 });

console.log(“rows”, dataRows);

// above console log will print

  [
  createData(1, "dashboard", "details"),
  createData(2, "product", "product details"),
 ]

Just pass dataRows to material-UI table

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.