6

I'm currently using Redux to fetch data from an API. I am then using this data to populate a DataGrid component from Material-UI. Below is what the api response looks like:API Response

Below is what I currently have setup for the column definitions:

Column Definitions enter image description here

The DataGrid seems to be able to recognize the id field from the results, as seen below, however, I cannot seem to drill down into attributes to get further details.

enter image description here

I'm looking for a solution that will allow me to display the attribute data, along with the id. All help is appretiated, thank you!

2 Answers 2

7

You can use valueGetter:

const columns = [
  // ...
  {
    field: 'attributeName',
    headerName: 'Attribute Name',
    valueGetter: (params) => {
      return params.getValue(params.id, "attributes").name;
    }
  },
  // ...
];

You may also need a sortComparator to handle the sorting of this column.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this solved my issue. I really appreciate your help!
1

try something like this to map the data out obviously change around the names as needed

const detailsRows = rows.map((row) => {
return {
  id: row.item_id,
  model: row.model_no,
  title: row.title,
};

and then pass it in to DataGrid like this

<DataGrid rows={detailsRows} columns={props.columns} pageSize={10}/>

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.