Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to display the name of Item in Material-UI Data Grid

Am using DataGrid from material UI react to display my data.

my database is like this:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this is my column code

const columns = [
      { field: 'user_id', headerName: 'User',flex: 1},
      { field: 'item_id', headerName: 'Item',flex: 1},
      { field: 'status', headerName: 'Status',flex: 1},
      { field: 'prepared_by', headerName: 'Prepared By',flex: 1},
      { field: 'date_ordered', headerName: 'Date Ordered',flex: 1},
      { field: 'date_received', headerName: 'Date Received',flex: 1},
    ];

current output

enter image description here

I tried this one but its showing blank

{ field: 'user_id.name', headerName: 'User',flex: 1},

Hope someone can help.

Thanks

>Solution :

you can map your data and add new property as field of column

sth like this :

<DataGrid
          rows={data.map(item=>({
            ...item,
            username:item.user_id?.name
          }))}
...

and new column row :

 { field: 'username', headerName: 'User',flex: 1},
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading