import React, { useState } from 'react'; import { DownOutlined } from '@ant-design/icons'; import type { RadioChangeEvent } from 'antd'; import { Form, Radio, Space, Switch, Table, ConfigProvider } from 'antd'; import type { SizeType } from 'antd/es/config-provider/SizeContext'; import type { ColumnsType, TableProps } from 'antd/es/table'; import type { ExpandableConfig, TableRowSelection } from 'antd/es/table/interface'; interface DataType { key: number; name: string; age: number; address: string; description: string; } type TablePaginationPosition = | 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight'; const columns: ColumnsType = [ { title: 'Name', dataIndex: 'name', }, { title: 'Age', dataIndex: 'age', sorter: (a, b) => a.age - b.age, }, { title: 'Address', dataIndex: 'address', filters: [ { text: 'London', value: 'London', }, { text: 'New York', value: 'New York', }, ], onFilter: (value, record) => record.address.indexOf(value as string) === 0, }, { title: 'Action', key: 'action', sorter: true, render: () => ( Delete More actions ), }, ]; const data: DataType[] = []; for (let i = 1; i <= 10; i++) { data.push({ key: i, name: 'John Brown', age: Number(`${i}2`), address: `New York No. ${i} Lake Park`, description: `My name is John Brown, I am ${i}2 years old, living in New York No. ${i} Lake Park.`, }); } const defaultExpandable = { expandedRowRender: (record: DataType) =>

{record.description}

}; const defaultTitle = () => 'Here is title'; const defaultFooter = () => 'Here is footer'; const App: React.FC = () => { const [bordered, setBordered] = useState(false); const [loading, setLoading] = useState(false); const [size, setSize] = useState('large'); const [expandable, setExpandable] = useState | undefined>( defaultExpandable, ); const [showTitle, setShowTitle] = useState(false); const [showHeader, setShowHeader] = useState(true); const [showfooter, setShowFooter] = useState(true); const [rowSelection, setRowSelection] = useState | undefined>({}); const [hasData, setHasData] = useState(true); const [tableLayout, setTableLayout] = useState(); const [top, setTop] = useState('none'); const [bottom, setBottom] = useState('bottomRight'); const [ellipsis, setEllipsis] = useState(false); const [yScroll, setYScroll] = useState(false); const [xScroll, setXScroll] = useState(); const handleBorderChange = (enable: boolean) => { setBordered(enable); }; const handleLoadingChange = (enable: boolean) => { setLoading(enable); }; const handleSizeChange = (e: RadioChangeEvent) => { setSize(e.target.value); }; const handleTableLayoutChange = (e: RadioChangeEvent) => { setTableLayout(e.target.value); }; const handleExpandChange = (enable: boolean) => { setExpandable(enable ? defaultExpandable : undefined); }; const handleEllipsisChange = (enable: boolean) => { setEllipsis(enable); }; const handleTitleChange = (enable: boolean) => { setShowTitle(enable); }; const handleHeaderChange = (enable: boolean) => { setShowHeader(enable); }; const handleFooterChange = (enable: boolean) => { setShowFooter(enable); }; const handleRowSelectionChange = (enable: boolean) => { setRowSelection(enable ? {} : undefined); }; const handleYScrollChange = (enable: boolean) => { setYScroll(enable); }; const handleXScrollChange = (e: RadioChangeEvent) => { setXScroll(e.target.value); }; const handleDataChange = (newHasData: boolean) => { setHasData(newHasData); }; const scroll: { x?: number | string; y?: number | string } = {}; if (yScroll) { scroll.y = 240; } if (xScroll) { scroll.x = '100vw'; } const tableColumns = columns.map((item) => ({ ...item, ellipsis })); if (xScroll === 'fixed') { tableColumns[0].fixed = true; tableColumns[tableColumns.length - 1].fixed = 'right'; } const tableProps: TableProps = { bordered, loading, size, expandable, title: showTitle ? defaultTitle : undefined, showHeader, footer: showfooter ? defaultFooter : undefined, rowSelection, scroll, tableLayout, }; return ( <>
Large Middle Small Unset Scroll Fixed Columns Unset Fixed { setTop(e.target.value); }} > TopLeft TopCenter TopRight None { setBottom(e.target.value); }} > BottomLeft BottomCenter BottomRight None
); }; export default App;