2016-09-09 13:55:41 +08:00
|
|
|
---
|
2019-11-15 14:35:25 +08:00
|
|
|
order: 22
|
2016-09-09 13:55:41 +08:00
|
|
|
title:
|
|
|
|
en-US: Grouping table head
|
|
|
|
zh-CN: 表头分组
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
`columns[n]` 可以内嵌 `children`,以渲染分组表头。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2016-11-15 12:01:06 +08:00
|
|
|
Group table head with `columns[n].children`.
|
2016-09-09 13:55:41 +08:00
|
|
|
|
2017-02-13 10:55:53 +08:00
|
|
|
```jsx
|
2016-09-09 13:55:41 +08:00
|
|
|
import { Table } from 'antd';
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
key: 'name',
|
|
|
|
width: 100,
|
|
|
|
fixed: 'left',
|
|
|
|
filters: [
|
|
|
|
{
|
|
|
|
text: 'Joe',
|
|
|
|
value: 'Joe',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'John',
|
|
|
|
value: 'John',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
onFilter: (value, record) => record.name.indexOf(value) === 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Other',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'Age',
|
|
|
|
dataIndex: 'age',
|
|
|
|
key: 'age',
|
2019-10-18 13:46:02 +08:00
|
|
|
width: 150,
|
2019-05-07 14:57:32 +08:00
|
|
|
sorter: (a, b) => a.age - b.age,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Address',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'Street',
|
|
|
|
dataIndex: 'street',
|
|
|
|
key: 'street',
|
2019-10-18 13:46:02 +08:00
|
|
|
width: 150,
|
2019-05-07 14:57:32 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Block',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'Building',
|
|
|
|
dataIndex: 'building',
|
|
|
|
key: 'building',
|
|
|
|
width: 100,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Door No.',
|
|
|
|
dataIndex: 'number',
|
|
|
|
key: 'number',
|
|
|
|
width: 100,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Company',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'Company Address',
|
|
|
|
dataIndex: 'companyAddress',
|
|
|
|
key: 'companyAddress',
|
2019-06-04 23:41:32 +08:00
|
|
|
width: 200,
|
2019-05-07 14:57:32 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Company Name',
|
|
|
|
dataIndex: 'companyName',
|
|
|
|
key: 'companyName',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Gender',
|
|
|
|
dataIndex: 'gender',
|
|
|
|
key: 'gender',
|
|
|
|
width: 80,
|
|
|
|
fixed: 'right',
|
|
|
|
},
|
|
|
|
];
|
2016-09-09 13:55:41 +08:00
|
|
|
|
|
|
|
const data = [];
|
|
|
|
for (let i = 0; i < 100; i++) {
|
|
|
|
data.push({
|
|
|
|
key: i,
|
2016-10-02 08:32:04 +08:00
|
|
|
name: 'John Brown',
|
2016-11-22 13:43:53 +08:00
|
|
|
age: i + 1,
|
2016-10-02 08:32:04 +08:00
|
|
|
street: 'Lake Park',
|
|
|
|
building: 'C',
|
2016-09-09 13:55:41 +08:00
|
|
|
number: 2035,
|
2016-10-02 08:32:04 +08:00
|
|
|
companyAddress: 'Lake Street 42',
|
|
|
|
companyName: 'SoftLake Co',
|
|
|
|
gender: 'M',
|
2016-09-09 13:55:41 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-03 23:27:45 +08:00
|
|
|
export default () => (
|
2016-09-09 13:55:41 +08:00
|
|
|
<Table
|
|
|
|
columns={columns}
|
|
|
|
dataSource={data}
|
2016-11-15 12:01:06 +08:00
|
|
|
bordered
|
|
|
|
size="middle"
|
2019-10-18 13:46:02 +08:00
|
|
|
scroll={{ x: 'calc(700px + 50%)', y: 240 }}
|
2022-04-03 23:27:45 +08:00
|
|
|
/>
|
2018-11-28 15:00:03 +08:00
|
|
|
);
|
2016-09-09 13:55:41 +08:00
|
|
|
```
|