-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Sorting in a DataGrid with many columns can shift rows in relation to the column headers #3890
Comments
I have found the culprit: setting columnBuffer property to a high enough number (number of all columns) fixes this issue. Thus the problem must lie in the column virtualization. |
It's a regression introduced in v5.0.0-beta.5 (Release notes). Virtualization was reworked in #2673 |
@DomenHocevar Thanks for opening a ticket on this, I just ran into the same issue :)) |
For me, setting it to around 55% of total columns worked fine. |
I investigated a bit on this bug. Here is what seems to append: When sorting the columns, the virtualization is modified. The first column to be rendered is updated. A workaround is to set Here is a demo to experiment with the bug and the fix. As you can see the column "D" content move when sorting except if we set https://codesandbox.io/s/datagriddemo-material-demo-forked-9ch1rg?file=/demo.tsx |
To fix this, I propose to move the In const renderedAreaMoved = (firstRowToRender !== prevRenderBuffer.current.firstRowToRender)
|| (firstColumnToRender !== prevRenderBuffer.current.firstColumnToRender)
if (renderedAreaMoved) {
updateRenderZonePosition(nextRenderContext);
prevRenderBuffer.current = {
firstRowToRender,
firstColumnToRender
}
} |
@alexfauquette How about the following diff? diff --git a/packages/grid/x-data-grid/src/internals/hooks/features/virtualization/useGridVirtualScroller.tsx b/packages/grid/x-data-grid/src/internals/hooks/features/virtualization/useGridVirtualScroller.tsx
index 6b81921da..1b7c759fe 100644
--- a/packages/grid/x-data-grid/src/internals/hooks/features/virtualization/useGridVirtualScroller.tsx
+++ b/packages/grid/x-data-grid/src/internals/hooks/features/virtualization/useGridVirtualScroller.tsx
@@ -141,6 +141,7 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => {
const initialRenderContext = computeRenderContext();
prevRenderContext.current = initialRenderContext;
setRenderContext(initialRenderContext);
+ updateRenderZonePosition(initialRenderContext);
const { top, left } = scrollPosition.current!;
const params = { top, left, renderContext: initialRenderContext }; With #3218,
Note that column pinning also calls |
Duplicates
Latest version
Current behavior 😯
Take a look here https://codesandbox.io/s/datagriddemo-material-demo-forked-l2hp1?file=/demo.tsx
Screencast.2022-02-06.22.45.47.mp4
As you can see in the video, when scrolling somewhere to the middle and then scrolling a column, the rows seem to shift in relation to the column headers.
Expected behavior 🤔
Rows should not shift in relation to the column headers.
Steps to reproduce 🕹
https://codesandbox.io/s/datagriddemo-material-demo-forked-l2hp1?file=/demo.tsx
Context 🔦
I'm trying to support showing items, that have many properties, in the data grid.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: