Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data grid] How to change DataGrid Palette colors #12443

Closed
sydneyjodon-wk opened this issue Mar 13, 2024 · 7 comments 路 Fixed by #12614
Closed

[data grid] How to change DataGrid Palette colors #12443

sydneyjodon-wk opened this issue Mar 13, 2024 · 7 comments 路 Fixed by #12614
Assignees
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: theme Centered around the theming features support: commercial Support request from paid users

Comments

@sydneyjodon-wk
Copy link

sydneyjodon-wk commented Mar 13, 2024

The problem in depth

Hello 馃憢

Is there a way to change the DataGrid theme palette colors similar to how you can change component theme palette colors in other MUI components (i.e. for Alert you can change theme.palette.Alert.infoFilledBg)?

I specifically would like to change some of these variables in gridStyle - like containerBackground and pinnedBackground because our theme uses a different color for theme.palette.background.default, but we don't want the DataGrid header row or pinned rows/columns to be updated to that color:

Screenshot 2024-03-13 at 2 28 18鈥疨M

Is there a way to override these colors? Either through setting a palette variable specifically for DataGrid or some other way? We tried using style overrides to override the color, but we're having trouble finding each element to style override since the variable is used in so many places.

FYI this is in MUI-X v7 (next)

Here is a codesandbox demo of the same issue - https://codesandbox.io/p/sandbox/datagrid-palette-colors-example-575y79?file=%2Fsrc%2FDemo.tsx%3A52%2C9

Thank you!

Search keywords: palette, pinnedBackground, containerBackground
Order ID: 82849

@sydneyjodon-wk sydneyjodon-wk added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Mar 13, 2024
@romgrk
Copy link
Contributor

romgrk commented Mar 13, 2024

For the time being you can use --DataGrid-pinnedBackground: #123456 !important on .MuiDataGrid-root (either via CSS or via the sx prop). This may cause issues with the hover/selected styles if the colors don't match closely though.

Waiting for feedback from the rest of the team, but we'll probably be adding shortly a more formal method to override the style variables.

@romgrk romgrk added the component: data grid This is the name of the generic UI component, not the React module! label Mar 13, 2024
@sydneyjodon-wk
Copy link
Author

Perfect! Thank you, @romgrk !

@michelengelen
Copy link
Member

Hey @sydneyjodon-wk ... there are actually 2 more ways to accomplish this:

  1. you can use styled and create a styled DataGrid ...
  2. ... or, more in line with your current approach, you can use themeAugmentation and add styleOverrides to your theme for the MuiDataGrid component.

@romgrk the pinned rows do not get a class applied that shows that they are pinned so we cannot target that. Is that intentional?

I have updated your example here

Would that be suficient for you?

@michelengelen michelengelen added status: waiting for author Issue with insufficient information customization: theme Centered around the theming features and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 14, 2024
@michelengelen michelengelen changed the title [question] How to change DataGrid Palette colors [data grid] How to change DataGrid Palette colors Mar 14, 2024
@sydneyjodon-wk
Copy link
Author

sydneyjodon-wk commented Mar 14, 2024

Thank you, @michelengelen - yes, it looks like updating using style overrides to override those variables will work for us - I didn't know you could do that! Thank you!

Like @romgrk mentioned, the hover state still gets the background.default color - which for us isn't a huge issue since our colors aren't as far off as that example I linked, but would there be a way to have the hover and selected colors pull from that variable too or something?

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Mar 14, 2024
@romgrk
Copy link
Contributor

romgrk commented Mar 14, 2024

Not for now, you'd need to add the hover/selected styles yourself. We'll update here as soon as we have a better styling solution.

@romgrk
Copy link
Contributor

romgrk commented Mar 29, 2024

I have opened #12614, the customization API would look something like this. If you have any comments feel free to share.

Copy link

鈿狅笍 This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@sydneyjodon-wk: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: theme Centered around the theming features support: commercial Support request from paid users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants