Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions docs/examples/scrollXY.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import Table from 'rc-table';
import '../../assets/index.less';

const columns: TableProps['columns'] = [
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'start' },
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
{ title: 'title3', dataIndex: 'c', key: 'c', width: 100, fixed: 'start' },
{ title: 'title4', dataIndex: 'b', key: 'd', width: 100 },
{ title: 'title5', dataIndex: 'b', key: 'e', width: 100 },
{ title: 'title6', dataIndex: 'b', key: 'f', width: 100 },
{ title: 'title1', dataIndex: 'a', key: 'a', width: 60, fixed: 'start' },
{ title: 'title2', dataIndex: 'b', key: 'b', width: 80, fixed: 'start' },
{ title: 'title3', dataIndex: 'c', key: 'c', width: 120 },
{ title: 'title4', dataIndex: 'b', key: 'd', width: 100, fixed: 'start' },
{ title: 'title5', dataIndex: 'b', key: 'e' },
{ title: 'title6', dataIndex: 'b', key: 'f' },
{ title: 'title7', dataIndex: 'b', key: 'g', width: 100 },
{ title: 'title8', dataIndex: 'b', key: 'h', width: 100 },
{ title: 'title9', dataIndex: 'b', key: 'i', width: 100 },
Expand Down
8 changes: 6 additions & 2 deletions src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface CellProps<RecordType extends DefaultRecordType> {
fixEnd?: number | false;
fixedStartShadow?: boolean;
fixedEndShadow?: boolean;
offsetFixedStartShadow?: number;
offsetFixedEndShadow?: number;
zIndex?: number;
allColsFixedLeft?: boolean;

Expand Down Expand Up @@ -107,6 +109,8 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
fixEnd,
fixedStartShadow,
fixedEndShadow,
offsetFixedStartShadow,
offsetFixedEndShadow,
zIndex,

// Private
Expand Down Expand Up @@ -146,12 +150,12 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
const showStartShadow =
(isFixStart && fixedStartShadow && absScroll) -
// For precision, we not show shadow by default which has better user experience.
(fixStart as number) >=
(offsetFixedStartShadow as number) >=
1;
const showEndShadow =
(isFixEnd && fixedEndShadow && scrollWidth - absScroll) -
// Same as above
(fixEnd as number) >=
(offsetFixedEndShadow as number) >=
1;

return [showStartShadow, showEndShadow];
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useStickyOffsets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function useStickyOffsets<RecordType>(
return {
start: startOffsets,
end: endOffsets,
widths: colWidths,
};
}, [colWidths, flattenColumns]);

Expand Down
1 change: 1 addition & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export type GetRowKey<RecordType> = (record: RecordType, index?: number) => Key;
export interface StickyOffsets {
start: readonly number[];
end: readonly number[];
widths: readonly number[];
isSticky?: boolean;
}

Expand Down
30 changes: 28 additions & 2 deletions src/utils/fixUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface FixedInfo {
/** `fixed: end` with shadow */
fixedEndShadow?: boolean;

/** Show the shadow when `scrollLeft` arrive for `fixed: start` */
offsetFixedStartShadow?: number;
/** Show the shadow when `scrollLeft` arrive for `fixed: end` */
offsetFixedEndShadow?: number;

zIndex?: number;
}

Expand Down Expand Up @@ -41,8 +46,8 @@ export function getCellFixedInfo(
}

// check if need to add shadow
let fixedStartShadow: boolean;
let fixedEndShadow: boolean;
let fixedStartShadow = false;
let fixedEndShadow = false;

// Calc `zIndex`.
// first fixed start (start -> end) column `zIndex` should be greater than next column.
Expand All @@ -58,11 +63,32 @@ export function getCellFixedInfo(
zIndex = colEnd;
}

// Check if scrollLeft will show the shadow
let offsetFixedStartShadow = 0;
let offsetFixedEndShadow = 0;

if (fixedStartShadow) {
for (let i = 0; i < colStart; i += 1) {
if (!isFixedStart(columns[i])) {
offsetFixedStartShadow += stickyOffsets.widths[i] || 0;
}
}
}
if (fixedEndShadow) {
for (let i = columns.length - 1; i > colEnd; i -= 1) {
if (!isFixedEnd(columns[i])) {
offsetFixedEndShadow += stickyOffsets.widths[i] || 0;
}
}
}

return {
fixStart,
fixEnd,
fixedStartShadow,
fixedEndShadow,
offsetFixedStartShadow,
offsetFixedEndShadow,
isSticky: stickyOffsets.isSticky,
zIndex,
};
Expand Down