|
| 1 | +import React from 'react'; |
| 2 | +import '../../assets/index.less'; |
| 3 | +import { VirtualTable } from '../../src'; |
| 4 | +import type { ColumnsType } from '../../src/interface'; |
| 5 | + |
| 6 | +interface RecordType { |
| 7 | + a: string; |
| 8 | + b?: string; |
| 9 | + c?: string; |
| 10 | +} |
| 11 | + |
| 12 | +const columns1: ColumnsType = [ |
| 13 | + { title: 'title1', dataIndex: 'a', width: 100 }, |
| 14 | + { title: 'title2', dataIndex: 'b', width: 100 }, |
| 15 | + { |
| 16 | + title: 'title13', |
| 17 | + dataIndex: 'c', |
| 18 | + }, |
| 19 | +]; |
| 20 | + |
| 21 | +const columns2: ColumnsType = [ |
| 22 | + { title: 'title1', dataIndex: 'a', width: 100 }, |
| 23 | + { title: 'title2', dataIndex: 'b', width: 100 }, |
| 24 | +]; |
| 25 | + |
| 26 | +const columns3: ColumnsType = [ |
| 27 | + { title: 'title1', dataIndex: 'a', width: 500 }, |
| 28 | + { title: 'title2', dataIndex: 'b', width: 500 }, |
| 29 | +]; |
| 30 | + |
| 31 | +const data: RecordType[] = new Array(4 * 10000).fill(null).map((_, index) => ({ |
| 32 | + a: `a${index}`, |
| 33 | + b: `b${index}`, |
| 34 | + c: `c${index}`, |
| 35 | +})); |
| 36 | + |
| 37 | +const Demo = () => { |
| 38 | + const [columns, setColumns] = React.useState(columns1); |
| 39 | + |
| 40 | + return ( |
| 41 | + <div style={{ width: 800, padding: `0 64px` }}> |
| 42 | + <label> |
| 43 | + <input type="radio" checked={columns === columns1} onChange={() => setColumns(columns1)} /> |
| 44 | + Fill Rest |
| 45 | + </label> |
| 46 | + <label> |
| 47 | + <input type="radio" checked={columns === columns2} onChange={() => setColumns(columns2)} /> |
| 48 | + Stretch |
| 49 | + </label> |
| 50 | + <label> |
| 51 | + <input type="radio" checked={columns === columns3} onChange={() => setColumns(columns3)} /> |
| 52 | + Over Size |
| 53 | + </label> |
| 54 | + |
| 55 | + <VirtualTable |
| 56 | + getContainerWidth={(_, w) => w - 1} |
| 57 | + columns={columns} |
| 58 | + scroll={{ y: 200 }} |
| 59 | + data={data} |
| 60 | + rowKey="a" |
| 61 | + /> |
| 62 | + </div> |
| 63 | + ); |
| 64 | +}; |
| 65 | + |
| 66 | +export default Demo; |
0 commit comments