在 Ant Design 中,我们可以使用 expandable 属性来实现可展开列。在展开前,我们可以看到每一行的表头都是一致的。但是展开后,除了默认显示的内容外,我们也需要显示可展开列的标题,此时就需要给可展开列命名。
我们可以通过 renderExpandIcon 方法来渲染可展开列的标题。代码示例如下:
import { Table } from 'antd';
const data = [
{
key: '1',
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park',
description: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',
},
{
key: '2',
name: 'Jim Green',
age: 42,
address: 'London No. 1 Lake Park',
description: 'My name is Jim Green, I am 42 years old, living in London No. 1 Lake Park.',
},
{
key: '3',
name: 'Joe Black',
age: 32,
address: 'Sidney No. 1 Lake Park',
description: 'My name is Joe Black, I am 32 years old, living in Sidney No. 1 Lake Park.',
},
];
class Demo extends React.Component {
expandedRowRender = () => {
const columns = [
{ title: 'Name', dataIndex: 'name', key: 'name' },
{ title: 'Age', dataIndex: 'age', key: 'age' },
{ title: 'Address', dataIndex: 'address', key: 'address' },
{
title: 'Description',
dataIndex: 'description',
key: 'description',
},
];
return
;
};
render() {
const columns = [
{ title: 'Name', dataIndex: 'name', key: 'name' },
{ title: 'Age', dataIndex: 'age', key: 'age' },
{ title: 'Address', dataIndex: