mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-22 22:48:29 +08:00
14a1e6bd51
* feat: tsconfig enable strict * feat: add no-explicit-any * feat: strict * feat: as THEME * feat: 优化 keys 类型写法 * feat: demo remove any * feat: as number * feat: this any * feat: add eslint * feat: cascader * feat: props any * feat: remove any * feat: remove any * feat: any 提示错误 * feat: remove any * feat: add eslint * feat: 允许 T = any 存在 * feat: color funciton * feat: 恢复 lint * feat: merge master * feat: as ReactElement * feat: type
121 lines
2.2 KiB
TypeScript
121 lines
2.2 KiB
TypeScript
import React from 'react';
|
|
import { Table } from 'antd';
|
|
import type { TableProps } from 'antd';
|
|
|
|
interface DataType {
|
|
key: string;
|
|
name: string;
|
|
age: number;
|
|
tel: string;
|
|
phone: number;
|
|
address: string;
|
|
}
|
|
|
|
// In the fifth row, other columns are merged into first column
|
|
// by setting it's colSpan to be 0
|
|
const sharedOnCell = (_: DataType, index?: number) => {
|
|
if (index === 1) {
|
|
return { colSpan: 0 };
|
|
}
|
|
|
|
return {};
|
|
};
|
|
|
|
const columns: TableProps<DataType>['columns'] = [
|
|
{
|
|
title: 'RowHead',
|
|
dataIndex: 'key',
|
|
rowScope: 'row',
|
|
},
|
|
{
|
|
title: 'Name',
|
|
dataIndex: 'name',
|
|
render: (text) => <a>{text}</a>,
|
|
onCell: (_, index) => ({
|
|
colSpan: index === 1 ? 5 : 1,
|
|
}),
|
|
},
|
|
{
|
|
title: 'Age',
|
|
dataIndex: 'age',
|
|
onCell: sharedOnCell,
|
|
},
|
|
{
|
|
title: 'Home phone',
|
|
colSpan: 2,
|
|
dataIndex: 'tel',
|
|
onCell: (_, index) => {
|
|
if (index === 3) {
|
|
return { rowSpan: 2 };
|
|
}
|
|
// These two are merged into above cell
|
|
if (index === 4) {
|
|
return { rowSpan: 0 };
|
|
}
|
|
if (index === 1) {
|
|
return { colSpan: 0 };
|
|
}
|
|
|
|
return {};
|
|
},
|
|
},
|
|
{
|
|
title: 'Phone',
|
|
colSpan: 0,
|
|
dataIndex: 'phone',
|
|
onCell: sharedOnCell,
|
|
},
|
|
{
|
|
title: 'Address',
|
|
dataIndex: 'address',
|
|
onCell: sharedOnCell,
|
|
},
|
|
];
|
|
|
|
const data: DataType[] = [
|
|
{
|
|
key: '1',
|
|
name: 'John Brown',
|
|
age: 32,
|
|
tel: '0571-22098909',
|
|
phone: 18889898989,
|
|
address: 'New York No. 1 Lake Park',
|
|
},
|
|
{
|
|
key: '2',
|
|
name: 'Jim Green',
|
|
tel: '0571-22098333',
|
|
phone: 18889898888,
|
|
age: 42,
|
|
address: 'London No. 1 Lake Park',
|
|
},
|
|
{
|
|
key: '3',
|
|
name: 'Joe Black',
|
|
age: 32,
|
|
tel: '0575-22098909',
|
|
phone: 18900010002,
|
|
address: 'Sydney No. 1 Lake Park',
|
|
},
|
|
{
|
|
key: '4',
|
|
name: 'Jim Red',
|
|
age: 18,
|
|
tel: '0575-22098909',
|
|
phone: 18900010002,
|
|
address: 'London No. 2 Lake Park',
|
|
},
|
|
{
|
|
key: '5',
|
|
name: 'Jake White',
|
|
age: 18,
|
|
tel: '0575-22098909',
|
|
phone: 18900010002,
|
|
address: 'Dublin No. 2 Lake Park',
|
|
},
|
|
];
|
|
|
|
const App: React.FC = () => <Table columns={columns} dataSource={data} bordered />;
|
|
|
|
export default App;
|