Skip to content

[DataGrid] Fix column spanning jump on scroll #17759

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

Merged
merged 1 commit into from
May 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions packages/x-data-grid/src/hooks/features/columns/gridColumnsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,16 +431,30 @@ export function getFirstNonSpannedColumnToRender({
visibleRows: GridRowEntry[];
}) {
let firstNonSpannedColumnToRender = firstColumnToRender;
for (let i = firstRowToRender; i < lastRowToRender; i += 1) {
const row = visibleRows[i];
if (row) {
const rowId = visibleRows[i].id;
const cellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(
rowId,
firstColumnToRender,
);
if (cellColSpanInfo && cellColSpanInfo.spannedByColSpan) {
firstNonSpannedColumnToRender = cellColSpanInfo.leftVisibleCellIndex;
let foundStableColumn = false;

// Keep checking columns until we find one that's not spanned in any visible row
while (!foundStableColumn && firstNonSpannedColumnToRender >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC firstNonSpannedColumnToRender is always >= 0

foundStableColumn = true;

for (let i = firstRowToRender; i < lastRowToRender; i += 1) {
const row = visibleRows[i];
if (row) {
const rowId = visibleRows[i].id;
const cellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(
rowId,
firstNonSpannedColumnToRender,
);

if (
Copy link
Contributor

@arminmeh arminmeh May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at certain scroll positions it seems that this code is called in intervals (don't think it is because of the changes made in this PR)

Screen.Recording.2025-05-09.at.14.42.59.mov

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Opened a separate PR for this one: #17779

cellColSpanInfo &&
cellColSpanInfo.spannedByColSpan &&
cellColSpanInfo.leftVisibleCellIndex < firstNonSpannedColumnToRender
) {
firstNonSpannedColumnToRender = cellColSpanInfo.leftVisibleCellIndex;
foundStableColumn = false;
break; // Check the new column index against the visible rows, because it might be spanned
}
}
}
}
Expand Down