import React from 'react'; import { Button, Segmented, Space, Switch, Table, Typography } from 'antd'; import type { TableProps } from 'antd'; interface RecordType { id: number; firstName: string; lastName: string; age: number; address1: string; address2: string; address3: string; } const fixedColumns: TableProps['columns'] = [ { title: 'ID', dataIndex: 'id', width: 100, fixed: 'left', }, { title: 'FistName', dataIndex: 'firstName', width: 120, fixed: 'left', }, { title: 'LastName', dataIndex: 'lastName', width: 120, fixed: 'left', }, { title: 'Group', width: 120, render: (_, record) => `Group ${Math.floor(record.id / 4)}`, onCell: (record) => ({ rowSpan: record.id % 4 === 0 ? 4 : 0, }), }, { title: 'Age', dataIndex: 'age', width: 100, onCell: (record) => ({ colSpan: record.id % 4 === 0 ? 2 : 1, }), }, { title: 'Address 1', dataIndex: 'address1', onCell: (record) => ({ colSpan: record.id % 4 === 0 ? 0 : 1, }), }, { title: 'Address 2', dataIndex: 'address2', }, { title: 'Address 3', dataIndex: 'address3', }, { title: 'Action', width: 150, fixed: 'right', render: () => ( Action1 Action2 ), }, ]; const columns: TableProps['columns'] = [ { title: 'ID', dataIndex: 'id', width: 100, }, { title: 'FistName', dataIndex: 'firstName', width: 120, }, { title: 'LastName', dataIndex: 'lastName', width: 120, }, ]; const getData = (count: number) => { const data: RecordType[] = new Array(count).fill(null).map((_, index) => ({ id: index, firstName: `First_${index.toString(16)}`, lastName: `Last_${index.toString(16)}`, age: 25 + (index % 10), address1: `New York No. ${index} Lake Park`, address2: `London No. ${index} Lake Park`, address3: `Sydney No. ${index} Lake Park`, })); return data; }; const App = () => { const [fixed, setFixed] = React.useState(true); const [bordered, setBordered] = React.useState(true); const [expanded, setExpanded] = React.useState(false); const [empty, setEmpty] = React.useState(false); const [count, setCount] = React.useState(10000); const tblRef: Parameters[0]['ref'] = React.useRef(null); const data = React.useMemo(() => getData(count), [count]); const mergedColumns = React.useMemo(() => { if (!fixed) { return columns; } if (!expanded) { return fixedColumns; } return fixedColumns.map((col) => ({ ...col, onCell: undefined })); }, [expanded, fixed]); const expandableProps = React.useMemo['expandable']>(() => { if (!expanded) { return undefined; } return { columnWidth: 48, expandedRowRender: (record) =>

🎉 Expanded {record.address1}

, rowExpandable: (record) => record.id % 2 === 0, }; }, [expanded]); return (
setBordered(!bordered)} checkedChildren="Bordered" unCheckedChildren="Bordered" /> setFixed(!fixed)} checkedChildren="Fixed" unCheckedChildren="Fixed" /> setExpanded(!expanded)} checkedChildren="Expandable" unCheckedChildren="Expandable" /> setEmpty(!empty)} checkedChildren="Empty" unCheckedChildren="Empty" /> setCount(value)} options={[ { label: 'None', value: 0, }, { label: 'Less', value: 4, }, { label: 'Lot', value: 10000, }, ]} /> {data.length >= 999 && ( )} ); }; export default App;