-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[DataGridPro] Fix pinned columns in RTL mode #14586
Changes from all commits
23f6140
7f4b453
d71a17e
aa06708
1470471
c285539
94aee23
ffa6ef0
e420963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -466,7 +466,6 @@ export const useGridVirtualScroller = () => { | |
const offsetLeft = computeOffsetLeft( | ||
columnPositions, | ||
currentRenderContext, | ||
isRtl, | ||
pinnedColumns.left.length, | ||
); | ||
const showBottomBorder = isLastVisibleInSection && params.position === 'top'; | ||
|
@@ -939,14 +938,11 @@ export function areRenderContextsEqual(context1: GridRenderContext, context2: Gr | |
export function computeOffsetLeft( | ||
columnPositions: number[], | ||
renderContext: GridColumnsRenderContext, | ||
isRtl: boolean, | ||
pinnedLeftLength: number, | ||
) { | ||
const factor = isRtl ? -1 : 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const left = | ||
factor * (columnPositions[renderContext.firstColumnIndex] ?? 0) - | ||
(columnPositions[renderContext.firstColumnIndex] ?? 0) - | ||
(columnPositions[pinnedLeftLength] ?? 0); | ||
|
||
return Math.abs(left); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,23 +166,31 @@ const findPinnedCells = ({ | |
return cells; | ||
}; | ||
|
||
export function findLeftPinnedCellsAfterCol(api: GridPrivateApiCommunity, col: HTMLElement) { | ||
export function findLeftPinnedCellsAfterCol( | ||
api: GridPrivateApiCommunity, | ||
col: HTMLElement, | ||
isRtl: boolean, | ||
) { | ||
const colIndex = parseCellColIndex(col); | ||
return findPinnedCells({ | ||
api, | ||
colIndex, | ||
position: 'left', | ||
filterFn: (index) => index > colIndex!, | ||
position: isRtl ? 'right' : 'left', | ||
filterFn: (index) => (isRtl ? index < colIndex! : index > colIndex!), | ||
Comment on lines
+178
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inverting the position and filter function fixes an issue where the other cells within the pinned columns were not being resized: Screen.Recording.2024-09-11.at.16.07.32.mov |
||
}); | ||
} | ||
|
||
export function findRightPinnedCellsBeforeCol(api: GridPrivateApiCommunity, col: HTMLElement) { | ||
export function findRightPinnedCellsBeforeCol( | ||
api: GridPrivateApiCommunity, | ||
col: HTMLElement, | ||
isRtl: boolean, | ||
) { | ||
const colIndex = parseCellColIndex(col); | ||
return findPinnedCells({ | ||
api, | ||
colIndex, | ||
position: 'right', | ||
filterFn: (index) => index < colIndex!, | ||
position: isRtl ? 'left' : 'right', | ||
filterFn: (index) => (isRtl ? index > colIndex! : index < colIndex!), | ||
}); | ||
} | ||
|
||
|
@@ -218,23 +226,31 @@ const findPinnedHeaders = ({ | |
return elements; | ||
}; | ||
|
||
export function findLeftPinnedHeadersAfterCol(api: GridPrivateApiCommunity, col: HTMLElement) { | ||
export function findLeftPinnedHeadersAfterCol( | ||
api: GridPrivateApiCommunity, | ||
col: HTMLElement, | ||
isRtl: boolean, | ||
) { | ||
const colIndex = parseCellColIndex(col); | ||
return findPinnedHeaders({ | ||
api, | ||
position: 'left', | ||
position: isRtl ? 'right' : 'left', | ||
colIndex, | ||
filterFn: (index) => index > colIndex!, | ||
filterFn: (index) => (isRtl ? index < colIndex! : index > colIndex!), | ||
}); | ||
} | ||
|
||
export function findRightPinnedHeadersBeforeCol(api: GridPrivateApiCommunity, col: HTMLElement) { | ||
export function findRightPinnedHeadersBeforeCol( | ||
api: GridPrivateApiCommunity, | ||
col: HTMLElement, | ||
isRtl: boolean, | ||
) { | ||
const colIndex = parseCellColIndex(col); | ||
return findPinnedHeaders({ | ||
api, | ||
position: 'right', | ||
position: isRtl ? 'left' : 'right', | ||
colIndex, | ||
filterFn: (index) => index < colIndex!, | ||
filterFn: (index) => (isRtl ? index > colIndex! : index < colIndex!), | ||
}); | ||
} | ||
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, we clearly missed this in Argos 👍🏻 |
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> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inverting these fixes an issue where pinned column viewport fillers were resizing the opposite sides:
Screen.Recording.2024-09-11.at.15.26.22.mov