Skip to content

Commit eac5ce8

Browse files
zombieJyoyo837
andauthored
feat: Support virtual Table (#1012)
* chore: init * chore: static of columns * feat: use virtual * refactor: extract func * chore: use internal hook * test: rm useless test * chore: support fixed * chore: scroll support * chore: scroll sync * chore: fixed pos * chore: fix style * chore: opt flatten * chore: part of it * chore: collect rows * chore: collect rowSpan * refactor: virtual cell * chore: rowSpan support * feat: rowSpan & colSpan * chore: row & col span * chore: update cal * fix: edge logic * chore: use fixed line * chore: use line align * chore: bump rc-virtual-list * chore: clean up * chore: refactor name * chore: use create immutable * chore: clean up * chore: bump rc-virtual-list * refactor: move useRowInfo in a single file * chore: tmp of columns * chore: fix sticky expand * refactor: move hooks * refactor: move hooks * chore: expanded support * chore: row expandable * chore: refactor name * refactor: row in * refactor: move rowClass in * chore: expanded info * chore: virtual * Update package.json Co-authored-by: Amumu <[email protected]> * chore: update span logic * 7.33.0-alpha.0 * feat: support listItemHeight * 7.33.0-alpha.1 * chore: nest of cell in row * 7.33.0-alpha.2 * fix: not render if no data * 7.33.0-alpha.3 * chore: add empty style * 7.33.0-alpha.4 * test: update testcase --------- Co-authored-by: Amumu <[email protected]>
1 parent 6f538dc commit eac5ce8

28 files changed

+1534
-276
lines changed

assets/index.less

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import 'virtual.less';
2+
13
@tablePrefixCls: rc-table;
24
@text-color: #666;
35
@font-size-base: 12px;
@@ -55,9 +57,11 @@
5557

5658
// ================== Cell ==================
5759
&-cell {
60+
background: #f4f4f4;
61+
5862
&-fix-left,
5963
&-fix-right {
60-
z-index: 1;
64+
z-index: 2;
6165
}
6266

6367
&-fix-right:last-child:not(&-fix-sticky) {
@@ -137,7 +141,7 @@
137141
}
138142

139143
&&-row-hover {
140-
background: rgba(255, 0, 0, 0.05);
144+
background: #fff4f4;
141145
}
142146
}
143147

assets/virtual.less

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@import (reference) 'index.less';
2+
3+
.@{tablePrefixCls}-tbody-virtual {
4+
* {
5+
box-sizing: border-box;
6+
}
7+
8+
@border: 1px solid @border-color;
9+
border-left: @border;
10+
11+
.@{tablePrefixCls}-row {
12+
display: flex;
13+
box-sizing: border-box;
14+
width: 100%;
15+
}
16+
17+
.@{tablePrefixCls}-row-extra {
18+
.@{tablePrefixCls}-cell {
19+
background: rgba(200, 200, 255) !important;
20+
}
21+
}
22+
23+
.@{tablePrefixCls}-cell {
24+
flex: 0 0 var(--virtual-width);
25+
width: var(--virtual-width);
26+
padding: 8px 16px;
27+
border-right: @border;
28+
border-bottom: @border;
29+
}
30+
}

docs/demo/virtual.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Virtual
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
7+
8+
<code src="../examples/virtual.tsx"></code>

docs/examples/virtual.tsx

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
import React from 'react';
2+
import '../../assets/index.less';
3+
import type { ColumnsType } from '../../src/interface';
4+
import { VirtualTable } from '../../src';
5+
6+
interface RecordType {
7+
a: string;
8+
b?: string;
9+
c?: string;
10+
d: number;
11+
indexKey: string;
12+
}
13+
14+
const columns: ColumnsType = [
15+
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' },
16+
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100, fixed: 'left', ellipsis: true },
17+
{
18+
title: 'title3',
19+
dataIndex: 'c',
20+
key: 'c',
21+
onCell: (_, index) => {
22+
if (index % 4 === 0) {
23+
return {
24+
rowSpan: 3,
25+
};
26+
}
27+
28+
if (index % 4 === 3) {
29+
return {
30+
rowSpan: 1,
31+
colSpan: 3,
32+
};
33+
}
34+
35+
return {
36+
rowSpan: 0,
37+
};
38+
},
39+
},
40+
{
41+
title: 'title4',
42+
key: 'd',
43+
children: [
44+
// Children columns
45+
{
46+
title: 'title4-1',
47+
dataIndex: 'b',
48+
onCell: (_, index) => {
49+
if (index % 4 === 0) {
50+
return {
51+
colSpan: 3,
52+
};
53+
}
54+
55+
if (index % 4 === 3) {
56+
return {
57+
colSpan: 0,
58+
};
59+
}
60+
},
61+
},
62+
{
63+
title: 'title4-2',
64+
dataIndex: 'b',
65+
onCell: (_, index) => {
66+
if (index % 4 === 0 || index % 4 === 3) {
67+
return {
68+
colSpan: 0,
69+
};
70+
}
71+
},
72+
},
73+
],
74+
},
75+
{
76+
title: 'title6',
77+
dataIndex: 'b',
78+
key: 'f',
79+
onCell: (_, index) => {
80+
if (index % 4 === 0) {
81+
return {
82+
rowSpan: 0,
83+
colSpan: 0,
84+
};
85+
}
86+
87+
if (index % 4 === 1) {
88+
return {
89+
rowSpan: 3,
90+
};
91+
}
92+
93+
return {
94+
rowSpan: 0,
95+
};
96+
},
97+
},
98+
{
99+
title: (
100+
<div>
101+
title7
102+
<br />
103+
<br />
104+
<br />
105+
Hello world!
106+
</div>
107+
),
108+
dataIndex: 'bk',
109+
key: 'g',
110+
},
111+
{
112+
title: 'title8',
113+
dataIndex: 'b',
114+
onCell: (_, index) => {
115+
if (index % 2 === 0) {
116+
return {
117+
rowSpan: 2,
118+
colSpan: 2,
119+
};
120+
}
121+
122+
return {
123+
rowSpan: 0,
124+
};
125+
},
126+
},
127+
{
128+
title: 'title9 i',
129+
dataIndex: 'b',
130+
key: 'i',
131+
onCell: () => ({
132+
colSpan: 0,
133+
}),
134+
},
135+
{ title: 'title10', dataIndex: 'b', key: 'j' },
136+
{
137+
title: 'title11',
138+
dataIndex: 'b',
139+
key: 'k',
140+
width: 50,
141+
fixed: 'right',
142+
onCell: (_, index) => {
143+
return {
144+
rowSpan: index % 2 === 0 ? 2 : 0,
145+
// colSpan: 2,
146+
};
147+
},
148+
},
149+
{
150+
title: 'title12',
151+
dataIndex: 'b',
152+
key: 'l',
153+
width: 100,
154+
fixed: 'right',
155+
onCell: () => {
156+
return {
157+
// colSpan: 0,
158+
};
159+
},
160+
},
161+
];
162+
163+
export function cleanOnCell(cols: any = []) {
164+
cols.forEach(col => {
165+
delete (col as any).onCell;
166+
167+
cleanOnCell((col as any).children);
168+
});
169+
}
170+
cleanOnCell(columns);
171+
172+
const data: RecordType[] = new Array(4 * 10000).fill(null).map((_, index) => ({
173+
a: `a${index}`,
174+
b: `b${index}`,
175+
c: `c${index}`,
176+
d: index,
177+
bk: <strong>Hello</strong>,
178+
indexKey: `${index}`,
179+
// children: [
180+
// {
181+
// indexKey: `${index}-1`,
182+
// },
183+
// {
184+
// indexKey: `${index}-2`,
185+
// },
186+
// ],
187+
}));
188+
189+
const Demo = () => {
190+
const [scrollY, setScrollY] = React.useState(true);
191+
192+
return (
193+
<div style={{ width: 800, padding: `0 64px` }}>
194+
<label>
195+
<input type="checkbox" checked={scrollY} onChange={() => setScrollY(!scrollY)} />
196+
Scroll Y
197+
</label>
198+
<VirtualTable
199+
columns={columns}
200+
// expandedRowRender={({ b, c }) => b || c}
201+
scroll={{ x: 1200, y: scrollY ? 200 : null }}
202+
data={data}
203+
// data={[]}
204+
rowKey="indexKey"
205+
expandable={{
206+
expandedRowRender: () => 2333,
207+
columnWidth: 60,
208+
expandedRowClassName: () => 'good-one',
209+
}}
210+
// onRow={() => ({ className: 'rowed' })}
211+
rowClassName="nice-try"
212+
/>
213+
</div>
214+
);
215+
};
216+
217+
export default Demo;

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-table",
3-
"version": "7.32.3",
3+
"version": "7.33.0-alpha.4",
44
"description": "table ui component for react",
55
"engines": {
66
"node": ">=8.x"
@@ -42,7 +42,7 @@
4242
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
4343
"test": "vitest",
4444
"coverage": "vitest run --coverage",
45-
"prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish",
45+
"prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish --branch static-table",
4646
"lint": "eslint src/ --ext .tsx,.ts",
4747
"lint:tsc": "tsc -p tsconfig.json --noEmit",
4848
"now-build": "npm run docs:build",
@@ -54,10 +54,11 @@
5454
},
5555
"dependencies": {
5656
"@babel/runtime": "^7.10.1",
57-
"@rc-component/context": "^1.3.0",
57+
"@rc-component/context": "^1.4.0",
5858
"classnames": "^2.2.5",
5959
"rc-resize-observer": "^1.1.0",
60-
"rc-util": "^5.27.1"
60+
"rc-util": "^5.36.0",
61+
"rc-virtual-list": "^3.10.4"
6162
},
6263
"devDependencies": {
6364
"@rc-component/father-plugin": "^1.0.2",

0 commit comments

Comments
 (0)