Skip to content

Commit 17d0bf2

Browse files
Mihran MargaryanMihran Margaryan
authored andcommitted
freeze right columns: calculations, hovers, groupings and shadows
1 parent e436e5e commit 17d0bf2

11 files changed

+465
-241
lines changed

packages/core/src/internal/data-grid/data-grid.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
480480
translateX,
481481
translateY,
482482
rows,
483-
freezeLeftColumns,
483+
freezeColumns,
484484
freezeTrailingRows,
485485
mappedColumns,
486486
rowHeight
@@ -508,7 +508,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
508508
translateX,
509509
translateY,
510510
rows,
511-
freezeLeftColumns,
511+
freezeColumns,
512512
freezeTrailingRows,
513513
mappedColumns,
514514
rowHeight,
@@ -1907,12 +1907,27 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
19071907
? 1
19081908
: clamp(-translateX / 100, 0, 1);
19091909

1910+
let translateXRight = 0;
1911+
1912+
if (eventTargetRef?.current) {
1913+
translateXRight = eventTargetRef?.current?.scrollLeft + width - eventTargetRef?.current?.scrollWidth;
1914+
}
1915+
19101916
const opacityXRight =
19111917
freezeRightColumns === 0 || !fixedShadowX
19121918
? 0
1913-
: cellXOffset + width < columns.length - freezeRightColumns
1919+
: cellXOffset +
1920+
getEffectiveColumns(
1921+
mappedColumns,
1922+
cellXOffset,
1923+
width,
1924+
freezeColumns,
1925+
dragAndDropState,
1926+
translateX
1927+
).filter(column => !column.sticky).length <
1928+
columns.length - freezeRightColumns
19141929
? 1
1915-
: clamp((translateX - (columns.length - freezeRightColumns - width) * 32) / 100, 0, 1);
1930+
: clamp(-translateXRight / 100, 0, 1);
19161931

19171932
const absoluteOffsetY = -cellYOffset * 32 + translateY;
19181933
const opacityY = !fixedShadowY ? 0 : clamp(-absoluteOffsetY / 100, 0, 1);

packages/core/src/internal/data-grid/render/data-grid-lib.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ export function getEffectiveColumns(
243243
width -= c.width;
244244
}
245245
}
246+
247+
const stickyRight: MappedGridColumn[] = [];
248+
249+
for (let i = mappedCols.length - freezeRightColumns; i < mappedCols.length; i++) {
250+
stickyRight.push(mappedCols[i]);
251+
}
252+
253+
if (stickyRight.length > 0) {
254+
for (const c of stickyRight) {
255+
width -= c.width;
256+
}
257+
}
258+
246259
let endIndex = cellXOffset;
247260
let curX = tx ?? 0;
248261

@@ -258,9 +271,7 @@ export function getEffectiveColumns(
258271
}
259272
}
260273

261-
for (let i = mappedCols.length - freezeRightColumns; i < mappedCols.length; i++) {
262-
sticky.push(mappedCols[i]);
263-
}
274+
sticky.push(...stickyRight);
264275

265276
return sticky;
266277
}

packages/core/src/internal/data-grid/render/data-grid-render.cells.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ export function drawCells(
132132
translateY,
133133
totalHeaderHeight,
134134
freezeTrailingColumns,
135-
(c, drawX, colDrawStartY, clipX, startRow) => {
135+
(c, drawX, colDrawStartY, clipX, clipXRight, startRow) => {
136136
const diff = Math.max(0, clipX - drawX);
137137

138138
const colDrawX = drawX + diff;
139139
const colDrawY = totalHeaderHeight + 1;
140-
const colWidth = c.width - diff;
140+
const colWidth = c.stickyPosition === "right" ? c.width - diff : Math.min(c.width - diff, width - drawX - clipXRight);
141141
const colHeight = height - totalHeaderHeight - 1;
142142
if (drawRegions.length > 0) {
143143
let found = false;
@@ -555,11 +555,11 @@ export function drawCell(
555555
partialPrepResult === undefined
556556
? undefined
557557
: {
558-
deprep: partialPrepResult?.deprep,
559-
fillStyle: partialPrepResult?.fillStyle,
560-
font: partialPrepResult?.font,
561-
renderer: r,
562-
};
558+
deprep: partialPrepResult?.deprep,
559+
fillStyle: partialPrepResult?.fillStyle,
560+
font: partialPrepResult?.font,
561+
renderer: r,
562+
};
563563
}
564564

565565
if (needsAnim || animationFrameRequested) enqueue?.(allocatedItem);

0 commit comments

Comments
 (0)