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 change the row background color in material ui datagrid?

I used a material ui data grid for showing some data.

import { DataGrid } from "@material-ui/data-grid"const 

columns = [
{
  id: "...",
  name: "...",      
},
...]
const rows = .....
<DataGrid rows={rows} columns={columns} autoHeight={true} />

Now I want to change the rows color based on their "name" property. I mean I want to set a different color for each row that has a different name. How should I do this?

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

>Solution :

MUI has an example for styling the rows that can be found here: https://mui.com/x/react-data-grid/style/#styling-rows

You’ll want to use the getRowClassName prop and provide it with a function with whatever logic you want to produce the classes you wish to style.

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