Skip to content

Commit 2a97994

Browse files
Mihran MargaryanMihran Margaryan
authored andcommitted
freeze right columns: calculations, hovers, groupings and shadows
1 parent 3ee044f commit 2a97994

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,
@@ -1908,12 +1908,27 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
19081908
? 1
19091909
: clamp(-translateX / 100, 0, 1);
19101910

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

19181933
const absoluteOffsetY = -cellYOffset * 32 + translateY;
19191934
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)