-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathexpandable.tsx
79 lines (70 loc) · 1.69 KB
/
expandable.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* copy this file to your working directory.
*/
import React, { FC, useState } from 'react';
import { useVT } from 'virtualizedtableforantd4';
import { Table } from 'antd';
function rndstr(str: string) {
const n = 0 | (Math.random() * 10) + 1;
let s = '';
for (let i = 0; i < n; ++i) {
s += str;
}
return s;
}
const _data: any[] = [];
for (let i = 0; i < 1000; i++) {
_data.push({
index: i,
name: `Edrward ${i}`,
expandable: ((Math.random() * 10) | 0) > 4,
age: 32,
address: rndstr(`London Park no. ${i}`),
});
}
const TableScrollTo: FC = () => {
const [expandedRowKeys, setExpandedRowKeys] = useState<string[]>([]);
const [VT] = useVT(() => {
return {
// ref: ref, // deprecated
initTop: 1000,
debug: true,
scroll: {
y: 600,
}
}
}, []);
return (
<>
<Table
columns={[{
title: 'index',
dataIndex: 'index',
}, {
title: 'address',
dataIndex: 'address',
}]}
scroll={{
y: 600,
}}
rowKey="index"
dataSource={_data}
components={VT}
expandable={{
expandedRowKeys,
onExpand: (expanded, record) => {
if (expanded) {
setExpandedRowKeys([...expandedRowKeys, record.index]);
} else {
const keys = expandedRowKeys.filter((k) => k !== record.index);
setExpandedRowKeys(keys);
}
},
expandedRowRender: record => <p style={{ margin: 0 }}>my name is {record.name}</p>,
rowExpandable: record => record.expandable,
}}
/>
</>
)
}
export default TableScrollTo;