2016-03-31 09:40:55 +08:00
|
|
|
---
|
2019-11-15 14:35:25 +08:00
|
|
|
order: 15
|
2016-08-15 07:54:01 +08:00
|
|
|
title:
|
|
|
|
en-US: colSpan and rowSpan
|
|
|
|
zh-CN: 表格行/列合并
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-10-29 15:38:59 +08:00
|
|
|
|
2016-08-15 07:54:01 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2015-10-29 20:10:44 +08:00
|
|
|
表头只支持列合并,使用 column 里的 colSpan 进行设置。
|
2015-10-29 15:38:59 +08:00
|
|
|
|
2015-11-05 19:35:21 +08:00
|
|
|
表格支持行/列合并,使用 render 里的单元格属性 colSpan 或者 rowSpan 设值为 0 时,设置的表格不会渲染。
|
2015-10-29 15:38:59 +08:00
|
|
|
|
2016-08-15 08:07:03 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
Table column title supports `colSpan` that set in `column`.
|
|
|
|
|
|
|
|
Table cell supports `colSpan` and `rowSpan` that set in render return object. When each of them is set to `0`, the cell will not be rendered.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2015-10-29 15:38:59 +08:00
|
|
|
import { Table } from 'antd';
|
|
|
|
|
2016-08-15 07:54:01 +08:00
|
|
|
// In the fifth row, other columns are merged into first column
|
|
|
|
// by setting it's colSpan to be 0
|
2016-11-15 12:01:06 +08:00
|
|
|
const renderContent = (value, row, index) => {
|
2016-07-21 18:05:15 +08:00
|
|
|
const obj = {
|
2015-10-29 15:38:59 +08:00
|
|
|
children: value,
|
2016-05-11 09:32:33 +08:00
|
|
|
props: {},
|
2015-11-25 17:35:49 +08:00
|
|
|
};
|
2015-10-29 16:23:09 +08:00
|
|
|
if (index === 4) {
|
2015-10-29 15:38:59 +08:00
|
|
|
obj.props.colSpan = 0;
|
|
|
|
}
|
|
|
|
return obj;
|
2015-10-29 20:14:08 +08:00
|
|
|
};
|
2015-10-29 15:38:59 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
render: (text, row, index) => {
|
|
|
|
if (index < 4) {
|
2019-08-14 19:36:59 +08:00
|
|
|
return <a>{text}</a>;
|
2019-05-07 14:57:32 +08:00
|
|
|
}
|
|
|
|
return {
|
2019-08-14 19:36:59 +08:00
|
|
|
children: <a>{text}</a>,
|
2019-05-07 14:57:32 +08:00
|
|
|
props: {
|
|
|
|
colSpan: 5,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2016-05-11 09:32:33 +08:00
|
|
|
},
|
2019-05-07 14:57:32 +08:00
|
|
|
{
|
|
|
|
title: 'Age',
|
|
|
|
dataIndex: 'age',
|
|
|
|
render: renderContent,
|
2016-05-11 09:32:33 +08:00
|
|
|
},
|
2019-05-07 14:57:32 +08:00
|
|
|
{
|
|
|
|
title: 'Home phone',
|
|
|
|
colSpan: 2,
|
|
|
|
dataIndex: 'tel',
|
|
|
|
render: (value, row, index) => {
|
|
|
|
const obj = {
|
|
|
|
children: value,
|
|
|
|
props: {},
|
|
|
|
};
|
|
|
|
if (index === 2) {
|
|
|
|
obj.props.rowSpan = 2;
|
|
|
|
}
|
|
|
|
// These two are merged into above cell
|
|
|
|
if (index === 3) {
|
|
|
|
obj.props.rowSpan = 0;
|
|
|
|
}
|
|
|
|
if (index === 4) {
|
|
|
|
obj.props.colSpan = 0;
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Phone',
|
|
|
|
colSpan: 0,
|
|
|
|
dataIndex: 'phone',
|
|
|
|
render: renderContent,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Address',
|
|
|
|
dataIndex: 'address',
|
|
|
|
render: renderContent,
|
|
|
|
},
|
|
|
|
];
|
2015-10-29 15:38:59 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
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: 'Sidney 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',
|
|
|
|
},
|
|
|
|
];
|
2015-10-29 15:38:59 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
ReactDOM.render(<Table columns={columns} dataSource={data} bordered />, mountNode);
|
|
|
|
```
|