Skip to content

Commit c281263

Browse files
committed
chore: rowSpan support
1 parent 5202ecc commit c281263

File tree

5 files changed

+59
-60
lines changed

5 files changed

+59
-60
lines changed

assets/virtual.less

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
display: flex;
1212
box-sizing: border-box;
1313
width: 100%;
14-
border-bottom: @border;
1514
border-left: @border;
1615
}
1716

@@ -20,9 +19,17 @@
2019
width: var(--virtual-width);
2120
padding: 8px 16px;
2221
border-right: @border;
22+
border-bottom: @border;
2323

2424
&-fix-left {
2525
left: calc(var(--sticky-left) + 1px) !important;
2626
}
27+
28+
&-virtual-fixed {
29+
position: absolute;
30+
z-index: 1;
31+
border-bottom: @border;
32+
left: calc(var(--sticky-left) + 1px) !important;
33+
}
2734
}
2835
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"classnames": "^2.2.5",
5959
"rc-resize-observer": "^1.1.0",
6060
"rc-util": "^5.27.1",
61-
"rc-virtual-list": "^3.10.0"
61+
"rc-virtual-list": "^3.10.1"
6262
},
6363
"devDependencies": {
6464
"@rc-component/father-plugin": "^1.0.2",

src/StaticTable/BodyGrid.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
4242
const flattenData = useFlattenRecords(data, childrenColumnName, expandedKeys, getRowKey);
4343

4444
// ========================== Column ==========================
45-
const columnsWidth = React.useMemo<[key: React.Key, width: number][]>(
46-
() => flattenColumns.map(({ width, key }) => [key, width as number]),
47-
[flattenColumns],
48-
);
45+
const columnsWidth = React.useMemo<[key: React.Key, width: number, total: number][]>(() => {
46+
let total = 0;
47+
return flattenColumns.map(({ width, key }) => {
48+
total += width as number;
49+
return [key, width as number, total];
50+
});
51+
}, [flattenColumns]);
4952

5053
React.useEffect(() => {
5154
columnsWidth.forEach(([key, width]) => {
@@ -84,7 +87,7 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
8487
};
8588

8689
const extraRender: ListProps<any>['extraRender'] = info => {
87-
const { start, end, getSize } = info;
90+
const { start, end, getSize, offsetY } = info;
8891

8992
// Find first rowSpan column
9093
const firstRowSpanColumns = flattenColumns.filter(column => getRowSpan(column, start) === 0);
@@ -126,17 +129,31 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
126129
const rowSpan = getRowSpan(column, i);
127130

128131
if (rowSpan > 1) {
129-
const endItem = flattenData[i + rowSpan - 1];
130-
console.log('!!!', i, rowSpan, endItem);
132+
const endItemIndex = i + rowSpan - 1;
133+
const endItem = flattenData[endItemIndex];
134+
const endKey = getRowKey(endItem.record, endItemIndex);
135+
136+
const sizeInfo = getSize(rowKey, endKey);
137+
const right = columnsWidth[colIndex][2];
138+
const left = columnsWidth[colIndex - 1][2] || 0;
139+
console.log('!!!', i, rowSpan, endItem, sizeInfo, right);
140+
131141
nodes.push(
132142
<RowSpanVirtualCell
143+
top={-offsetY + sizeInfo.top}
144+
height={sizeInfo.bottom - sizeInfo.top}
145+
left={left}
146+
width={right - left}
133147
key={`${i}_${colIndex}`}
134148
record={item.record}
135149
rowKey={rowKey}
136150
column={column}
137151
colIndex={colIndex}
138152
index={i}
139153
indent={0}
154+
style={{
155+
['--sticky-left' as any]: `${left}px`,
156+
}}
140157
/>,
141158
);
142159
}

src/StaticTable/BodyLine.tsx

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -47,53 +47,6 @@ const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) =>
4747
record={record}
4848
/>
4949
);
50-
// const { render, dataIndex, className: columnClassName, width: colWidth } = column;
51-
52-
// const { key, fixedInfo, appendCellNode, additionalCellProps } = getCellProps(
53-
// rowInfo,
54-
// column,
55-
// colIndex,
56-
// indent,
57-
// index,
58-
// );
59-
60-
// const { style: cellStyle, colSpan, rowSpan } = additionalCellProps;
61-
// const mergedStyle = {
62-
// ...cellStyle,
63-
// '--virtual-width': `${colWidth}px`,
64-
// };
65-
66-
// // When `colSpan` or `rowSpan` is `0`, should skip render.
67-
// const mergedRender =
68-
// colSpan === 0 || rowSpan === 0 || colSpan > 1 || rowSpan > 1 ? () => null : render;
69-
70-
// return (
71-
// <Cell
72-
// className={columnClassName}
73-
// ellipsis={column.ellipsis}
74-
// align={column.align}
75-
// scope={column.rowScope}
76-
// component="div"
77-
// prefixCls={prefixCls}
78-
// key={key}
79-
// record={record}
80-
// index={index}
81-
// renderIndex={record.index}
82-
// dataIndex={dataIndex}
83-
// render={mergedRender}
84-
// shouldCellUpdate={column.shouldCellUpdate}
85-
// {...fixedInfo}
86-
// appendNode={appendCellNode}
87-
// additionalProps={{
88-
// ...additionalCellProps,
89-
// style: mergedStyle,
90-
91-
// // Virtual should reset `colSpan` & `rowSpan`
92-
// rowSpan: 1,
93-
// colSpan: 1,
94-
// }}
95-
// />
96-
// );
9750
})}
9851
</div>
9952
);

src/StaticTable/VirtualCell.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import { getCellProps, useRowInfo } from '../Body/BodyRow';
33
import Cell from '../Cell';
44
import type { ColumnType } from '../interface';
5+
import classNames from 'classnames';
56

67
export interface VirtualCellProps<RecordType extends { index: number }> {
78
rowInfo: ReturnType<typeof useRowInfo>;
@@ -14,12 +15,13 @@ export interface VirtualCellProps<RecordType extends { index: number }> {
1415
// Follow props is used for RowSpanVirtualCell only
1516
forceRender?: boolean;
1617
style?: React.CSSProperties;
18+
className?: string;
1719
}
1820

1921
function VirtualCell<RecordType extends { index: number } = any>(
2022
props: VirtualCellProps<RecordType>,
2123
) {
22-
const { rowInfo, column, colIndex, indent, index, record, forceRender, style } = props;
24+
const { rowInfo, column, colIndex, indent, index, record, forceRender, style, className } = props;
2325

2426
const { render, dataIndex, className: columnClassName, width: colWidth } = column;
2527

@@ -46,7 +48,7 @@ function VirtualCell<RecordType extends { index: number } = any>(
4648

4749
return (
4850
<Cell
49-
className={columnClassName}
51+
className={classNames(columnClassName, className)}
5052
ellipsis={column.ellipsis}
5153
align={column.align}
5254
scope={column.rowScope}
@@ -73,20 +75,40 @@ function VirtualCell<RecordType extends { index: number } = any>(
7375
);
7476
}
7577

78+
// ================= Virtual Row Span Cell =================
7679
export interface RowSpanVirtualCellProps<RecordType extends { index: number }>
7780
extends Omit<VirtualCellProps<RecordType>, 'rowInfo'> {
7881
record: RecordType;
7982
rowKey: React.Key;
83+
top: number;
84+
height: number;
85+
left: number;
86+
width: number;
8087
}
8188

8289
export function RowSpanVirtualCell<RecordType extends { index: number } = any>(
8390
props: RowSpanVirtualCellProps<RecordType>,
8491
) {
85-
const { record, rowKey } = props;
92+
const { record, rowKey, top, height, left, width, style } = props;
8693

8794
const rowInfo = useRowInfo<RecordType>(record, rowKey);
95+
const { prefixCls } = rowInfo;
8896

89-
return <VirtualCell rowInfo={rowInfo} {...props} forceRender />;
97+
return (
98+
<VirtualCell
99+
rowInfo={rowInfo}
100+
{...props}
101+
style={{
102+
...style,
103+
top,
104+
height,
105+
left,
106+
width,
107+
}}
108+
className={`${prefixCls}-cell-virtual-fixed`}
109+
forceRender
110+
/>
111+
);
90112
}
91113

92114
export default VirtualCell;

0 commit comments

Comments
 (0)