-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataGridPro] Fix pinned columns in RTL mode (#14586)
- Loading branch information
1 parent
dd4447c
commit 2777772
Showing
6 changed files
with
151 additions
and
38 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import * as React from 'react'; | ||
import { prefixer } from 'stylis'; | ||
import rtlPlugin from 'stylis-plugin-rtl'; | ||
import { useGridApiRef, DataGridPro } from '@mui/x-data-grid-pro'; | ||
import { arSD } from '@mui/x-data-grid/locales'; | ||
import createCache from '@emotion/cache'; | ||
import { CacheProvider } from '@emotion/react'; | ||
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles'; | ||
|
||
// Create rtl cache | ||
const cacheRtl = createCache({ | ||
key: 'data-grid-rtl-demo', | ||
stylisPlugins: [prefixer, rtlPlugin], | ||
}); | ||
|
||
const columns = [ | ||
{ | ||
field: 'id', | ||
headerName: 'تعريف', | ||
width: 150, | ||
}, | ||
{ | ||
field: 'name', | ||
headerName: 'اسم', | ||
width: 150, | ||
}, | ||
{ | ||
field: 'age', | ||
headerName: 'عمر', | ||
valueGetter: (value) => `${value} سنوات`, | ||
width: 150, | ||
}, | ||
{ | ||
field: 'occupation', | ||
headerName: 'المهنة', | ||
width: 150, | ||
}, | ||
{ | ||
field: 'gender', | ||
headerName: 'جنس', | ||
width: 150, | ||
}, | ||
]; | ||
|
||
const rows = [ | ||
{ id: 1, name: 'سارہ', age: 35, occupation: 'معلم', gender: 'أنثى' }, | ||
{ id: 2, name: 'زید', age: 42, occupation: 'مهندس', gender: 'ذكر' }, | ||
{ id: 3, name: 'علی', age: 33, occupation: 'محاسب', gender: 'ذكر' }, | ||
{ id: 4, name: 'فاطمہ', age: 25, occupation: 'معلم', gender: 'أنثى' }, | ||
{ id: 5, name: 'ایندریو', age: 65, occupation: 'مهندس', gender: 'ذكر' }, | ||
]; | ||
|
||
export default function DataGridRTLPinnedColumns() { | ||
const apiRef = useGridApiRef(); | ||
const existingTheme = useTheme(); | ||
const theme = React.useMemo( | ||
() => | ||
createTheme({}, arSD, existingTheme, { | ||
direction: 'rtl', | ||
}), | ||
[existingTheme], | ||
); | ||
|
||
return ( | ||
<CacheProvider value={cacheRtl}> | ||
<ThemeProvider theme={theme}> | ||
<div dir="rtl" style={{ height: 500, width: '100%' }}> | ||
<DataGridPro | ||
apiRef={apiRef} | ||
rows={rows} | ||
columns={columns} | ||
initialState={{ | ||
pinnedColumns: { | ||
left: ['id', 'name'], | ||
right: ['occupation'], | ||
}, | ||
}} | ||
/> | ||
</div> | ||
</ThemeProvider> | ||
</CacheProvider> | ||
); | ||
} |