ant-design/components/table/demo/colspan-rowspan.md

126 lines
2.5 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 13
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.
2015-10-29 15:38:59 +08:00
````jsx
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
const renderContent = function (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-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
const columns = [{
title: '姓名',
dataIndex: 'name',
render(text, row, index) {
2015-10-29 16:23:09 +08:00
if (index < 4) {
return <a href="#">{text}</a>;
2015-10-29 15:38:59 +08:00
}
return {
children: <a href="#">{text}</a>,
props: {
2016-05-11 09:32:33 +08:00
colSpan: 5,
},
};
2016-05-11 09:32:33 +08:00
},
2015-10-29 16:23:09 +08:00
}, {
2015-10-29 15:38:59 +08:00
title: '年龄',
dataIndex: 'age',
2016-05-11 09:32:33 +08:00
render: renderContent,
2015-10-29 16:23:09 +08:00
}, {
2015-10-29 15:38:59 +08:00
title: '家庭电话',
colSpan: 2,
dataIndex: 'tel',
render(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-10-29 16:23:09 +08:00
if (index === 2) {
2015-10-29 15:38:59 +08:00
obj.props.rowSpan = 2;
}
2016-08-15 07:54:01 +08:00
// These two are merged into above cell
2015-10-29 16:23:09 +08:00
if (index === 3) {
2015-10-29 15:38:59 +08:00
obj.props.rowSpan = 0;
}
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;
2016-05-11 09:32:33 +08:00
},
2015-10-29 16:23:09 +08:00
}, {
2015-10-29 15:38:59 +08:00
title: '手机号',
colSpan: 0,
dataIndex: 'phone',
2016-05-11 09:32:33 +08:00
render: renderContent,
2015-10-29 16:23:09 +08:00
}, {
2015-10-29 15:38:59 +08:00
title: '住址',
dataIndex: 'address',
2016-05-11 09:32:33 +08:00
render: renderContent,
2015-10-29 15:38:59 +08:00
}];
const data = [{
key: '1',
name: '胡彦斌',
age: 32,
tel: '0571-22098909',
phone: 18889898989,
2016-05-03 14:15:29 +08:00
address: '西湖区湖底公园1号',
2015-10-29 15:38:59 +08:00
}, {
key: '2',
name: '胡彦祖',
tel: '0571-22098333',
phone: 18889898888,
age: 42,
2016-05-03 14:15:29 +08:00
address: '西湖区湖底公园1号',
2015-10-29 15:38:59 +08:00
}, {
key: '3',
name: '李大嘴',
age: 32,
tel: '0575-22098909',
phone: 18900010002,
2016-05-03 14:15:29 +08:00
address: '西湖区湖底公园1号',
2015-10-29 16:23:09 +08:00
}, {
2015-10-29 15:38:59 +08:00
key: '4',
name: '李夫人',
age: 18,
tel: '0575-22098909',
phone: 18900010002,
2016-05-03 14:15:29 +08:00
address: '西湖区湖底公园1号',
2015-10-29 16:23:09 +08:00
}, {
key: '5',
name: '习大大',
age: 18,
tel: '0575-22098909',
phone: 18900010002,
2016-05-03 14:15:29 +08:00
address: '西湖区湖底公园1号',
}];
2015-10-29 15:38:59 +08:00
2015-11-25 17:47:55 +08:00
ReactDOM.render(<Table columns={columns} dataSource={data} bordered />
, mountNode);
2015-10-29 15:38:59 +08:00
````