forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataGrid] Add indexes relative to the filtered rows and the current …
…page to the `getRowClassName` and `getRowSpacing` props (mui#3882)
- Loading branch information
1 parent
753275b
commit d9f2c13
Showing
10 changed files
with
179 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as React from 'react'; | ||
import { alpha, styled } from '@mui/material/styles'; | ||
import { DataGrid, gridClasses } from '@mui/x-data-grid'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
|
||
const ODD_OPACITY = 0.2; | ||
|
||
const StripedDataGrid = styled(DataGrid)(({ theme }) => ({ | ||
[`& .${gridClasses.row}.even`]: { | ||
backgroundColor: theme.palette.grey[200], | ||
'&:hover, &.Mui-hovered': { | ||
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, &.Mui-hovered': { | ||
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, | ||
), | ||
}, | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
export default function StripedGrid() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Employee', | ||
rowLength: 200, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<StripedDataGrid | ||
loading={loading} | ||
{...data} | ||
getRowClassName={(params) => | ||
params.indexRelativeToCurrentPage % 2 === 0 ? 'even' : 'odd' | ||
} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as React from 'react'; | ||
import { alpha, styled } from '@mui/material/styles'; | ||
import { DataGrid, gridClasses } from '@mui/x-data-grid'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
|
||
const ODD_OPACITY = 0.2; | ||
|
||
const StripedDataGrid = styled(DataGrid)(({ theme }) => ({ | ||
[`& .${gridClasses.row}.even`]: { | ||
backgroundColor: theme.palette.grey[200], | ||
'&:hover, &.Mui-hovered': { | ||
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, &.Mui-hovered': { | ||
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, | ||
), | ||
}, | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
export default function StripedGrid() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Employee', | ||
rowLength: 200, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<StripedDataGrid | ||
loading={loading} | ||
{...data} | ||
getRowClassName={(params) => | ||
params.indexRelativeToCurrentPage % 2 === 0 ? 'even' : 'odd' | ||
} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<StripedDataGrid | ||
loading={loading} | ||
{...data} | ||
getRowClassName={(params) => | ||
params.indexRelativeToCurrentPage % 2 === 0 ? 'even' : 'odd' | ||
} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters