|
| 1 | +import type { ColumnsType } from '@/interface'; |
| 2 | +import Table from 'rc-table'; |
| 3 | +import '../../assets/index.less'; |
| 4 | + |
| 5 | +interface FirstTableRecordType { |
| 6 | + lastName?: string; |
| 7 | + firstName?: string; |
| 8 | + city?: string; |
| 9 | + key?: string; |
| 10 | +} |
| 11 | + |
| 12 | +const firstTableColumns: ColumnsType<FirstTableRecordType> = [ |
| 13 | + { title: 'Last Name', dataIndex: 'lastName', key: 'lastName' }, |
| 14 | + { title: 'First Name', dataIndex: 'firstName', key: 'firstName' }, |
| 15 | + { title: 'City', dataIndex: 'city', key: 'city' }, |
| 16 | +]; |
| 17 | + |
| 18 | +const firstTableData: FirstTableRecordType[] = [ |
| 19 | + { lastName: 'Phoenix', firstName: 'Imary', city: 'Henry', key: '1' }, |
| 20 | + { lastName: 'Zeki', firstName: 'Rome', city: 'Min', key: '2' }, |
| 21 | + { lastName: 'Apirka', firstName: 'Kelly', city: 'Brynn', key: '3' }, |
| 22 | +]; |
| 23 | + |
| 24 | +interface SecondTableRecordType { |
| 25 | + productType?: string; |
| 26 | + producedMars?: string; |
| 27 | + soldMars?: string; |
| 28 | + producedVenus?: string; |
| 29 | + soldVenus?: string; |
| 30 | + key?: string; |
| 31 | +} |
| 32 | + |
| 33 | +const secondTableColumns: ColumnsType<SecondTableRecordType> = [ |
| 34 | + { |
| 35 | + title: '', |
| 36 | + dataIndex: 'productType', |
| 37 | + key: 'productType', |
| 38 | + rowSpan: 2, |
| 39 | + rowScope: 'row', |
| 40 | + }, |
| 41 | + { |
| 42 | + title: 'Mars', |
| 43 | + dataIndex: 'mars', |
| 44 | + key: 'mars', |
| 45 | + children: [ |
| 46 | + { title: 'Produced', dataIndex: 'producedMars', key: 'producedMars' }, |
| 47 | + { title: 'Sold', dataIndex: 'soldMars', key: 'soldMars' }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + { |
| 51 | + title: 'Venus', |
| 52 | + dataIndex: 'venus', |
| 53 | + key: 'venus', |
| 54 | + children: [ |
| 55 | + { title: 'Produced', dataIndex: 'producedVenus', key: 'producedVenus' }, |
| 56 | + { title: 'Sold', dataIndex: 'soldVenus', key: 'soldVenus' }, |
| 57 | + ], |
| 58 | + }, |
| 59 | +]; |
| 60 | + |
| 61 | +const secondTableData: SecondTableRecordType[] = [ |
| 62 | + { |
| 63 | + productType: 'Teddy Bears', |
| 64 | + producedMars: '50,000', |
| 65 | + soldMars: '30,000', |
| 66 | + producedVenus: '100,000', |
| 67 | + soldVenus: '80,000', |
| 68 | + key: '1', |
| 69 | + }, |
| 70 | + { |
| 71 | + productType: 'Board Games', |
| 72 | + producedMars: '10,000', |
| 73 | + soldMars: '5,000', |
| 74 | + producedVenus: '12,000', |
| 75 | + soldVenus: '9,000', |
| 76 | + key: '2', |
| 77 | + }, |
| 78 | +]; |
| 79 | + |
| 80 | +const Demo = () => ( |
| 81 | + <div> |
| 82 | + <h2>Scope col</h2> |
| 83 | + <Table<FirstTableRecordType> columns={firstTableColumns} data={firstTableData} /> |
| 84 | + <br /> |
| 85 | + <h2>Scope colgroup</h2> |
| 86 | + <Table<SecondTableRecordType> columns={secondTableColumns} data={secondTableData} /> |
| 87 | + </div> |
| 88 | +); |
| 89 | + |
| 90 | +export default Demo; |
0 commit comments