-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[data grid] Row css class for striped rows #13218
Comments
No, this is not the only way to do this, just one. const StripedDataGrid = styled(DataGridPremium)(({ theme }) => ({
[`& .${gridClasses.row}:nth-child(even)`]: {
backgroundColor: theme.palette.grey[200],
'&:hover': {
backgroundColor: alpha(theme.palette.primary.main, ODD_OPACITY),
'@media (hover: none)': {
backgroundColor: 'transparent',
},
},
'&.Mui-selected': {
backgroundColor: alpha(
theme.palette.primary.main,
ODD_OPACITY + theme.palette.action.selectedOpacity,
),
'&:hover': {
backgroundColor: alpha(
theme.palette.primary.main,
ODD_OPACITY +
theme.palette.action.selectedOpacity +
theme.palette.action.hoverOpacity,
),
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
backgroundColor: alpha(
theme.palette.primary.main,
ODD_OPACITY + theme.palette.action.selectedOpacity,
),
},
},
},
},
})); You could also do a global override with a custom theme if that is more convenient. |
notice the |
@michelengelen won't that flicker when you scroll due to virtualization? |
@michelengelen tanks for your reply. DataGridPremium-Striped.mov |
I think it could be useful to define a boolean striped property for DataGrid that automatically adds Mui-even / Mui-odd calsses with default styles when activated. Of course then developers can override and customize the style. What do you think? Many thanks, |
You should be able to set `getRowClassName in your theme so it applies on every data grid you have. |
@flaviendelangle how should I put getRowClassName in createTheme({...}) call? Mauro |
Ok, found:
|
Here is a working example It's pretty much what you have in your last message 👍 |
@flaviendelangle many thanks for your help! |
Great that we could be of help and thanks @flaviendelangle for providing a great example. |
@mauro-ni: 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. |
Playing with the new implementation I noticed that on pinned columns the stripe effect is lost. |
@michelengelen can I let you see how to support pinned columns? |
@flaviendelangle good morning, regarding the suggested approach for stripes (using alpha), I would like to point out that there is a problem when applying it to pinned columns: on scroll the content this is visible under the pinned columns. It would probably be better to use darken / lighten utilities. Another styling issue with v 7.5 is on DataGrid used inside Paper component: header and pinned columns get a darker background. I read about that in https://mui.com/x/migration/migration-data-grid-v6
Is there a way to globally handle that? |
As a temporary solution I managed the background customizing the theme as follows (inPaper is a prop that I set on DataGrid):
I don't like this solution, it is a workaround, but ... seems to work. Do you have a better solution for that? |
@mauro-ni this seems like a good way to handle the pinned background until we come up with a solid solution internally. Interestingly enough I. haven't noticed the header behavior before. Thanks for pointing that out. @flaviendelangle I had a codesandbox somewhere where I did implement that once ... just cannot find it anymore! 🤷🏼 But it is rather simple. Instead of targeting the row styles you can just as well target the cells:
|
Maybe we could adapt https://mui.com/x/react-data-grid/style/#striped-rows to handle pinned rows |
@michelengelen thank you for your help. Targeting the cell instead of the row with the code you suggested partially breaks hover effect.
|
Here is a temporary solution that, again, I don't like (there was an issue with the implementation with alpha() because pinned columns have forced background, and for now I force the backgrounds I want). I think that a boolean striped property on DataGrid / DataGridPro / DataGridPremium could be useful (maybe being able to specify hover & selection color).
|
The problem in depth
Good morning,
at https://mui.com/x/react-data-grid/style/#striped-rows you provide a solution to get striped rows.
You suggest to use getRowClassName as follows and then to apply the desired style using added classes.
Is there a way to automatically get even / odd classes by default?
I have around twenty DataGrid instances and I would avoid code repetition.
If I remember correctly, in past versions of mui-x the Mui-even and Mui-odd classes were included automatically. Were they removed for performance reasons?
Many thanks in advance.
Mauro
Your environment
`npx @mui/envinfo`
Search keywords: stripe striped zebra
Order ID: 47709
The text was updated successfully, but these errors were encountered: