-
Notifications
You must be signed in to change notification settings - Fork 48
/
scroll-to.tsx
99 lines (87 loc) · 1.92 KB
/
scroll-to.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React, { FC, useState, useRef } from 'react';
import { useVT } from 'virtualizedtableforantd4';
import { Table, Input, Button } 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}`,
age: 32,
address: rndstr(`London Park no. ${i}`),
});
}
const TableScrollTo: FC = () => {
const [top, setTop] = useState(-1);
const [idx, setIdx] = useState(0);
// const ref = useRef();
const [VT, _, ref/* new */] = useVT(() => {
return {
// ref: ref, // deprecated
initTop: 1000,
debug: true,
scroll: {
y: 600,
}
}
}, []);
return (
<>
scrollTo:
<Input
width={100}
onChange={e => {
const top = (+e.target.value);
setTop(Number.isNaN(top) ? 0 : top);
}}
/>
<Button
onClick={() => {
// ref.current.scrollTo(top) // deprecated
ref.current.scrollTo(top)
}}
>
{`jump to ${top === -1 ? 'the bottom of the table' : `top: ${top}`}`}
</Button>
<br />
scrollToIdx:
<Input
width={100}
onChange={e => {
const idx = (+e.target.value);
setIdx(Number.isNaN(idx) ? 0 : idx);
}}
/>
<Button
onClick={() => {
ref.current.scrollToIdx(idx)
}}
>
{`jump to the idx of the rows: ${idx}`}
</Button>
<Table
columns={[{
title: 'index',
dataIndex: 'index',
}, {
title: 'address',
dataIndex: 'address',
}]}
scroll={{
y: 600,
}}
dataSource={_data}
components={VT}
pagination={false}
/>
</>
)
}
export default TableScrollTo;