mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 13:18:04 +08:00
72a7ba618f
* chore: update rc-table * add basic table style * checked all logic * checkbox support disabled * selection style * selection support radio * add selections support * selection extra style * select all locale * sorter logic * add more desc * init Filter hooks * init filter hooks * update style * filter style * filter style * fix filter * sort control * ajax it * add expandedable css * expandable view style * fixed style * border style * empty style * fix pagination style * add fixed demo * un-comment * clean up * fix filter check logic * fix overflow & ellipsis conflict * fix tes * adjust scroll shadow * fix border fixed style * add part of test case * add filter test part * more test case * issue related test * filter test * adjust pagination logic * fix pagination test case * all selection test case * table sorter test case * table basic test * fix test case * update faq * update expandable doc * add v4 doc * add summary docs * more demo * fix selection * update snapshot * update test case * fix ff styling * update rc-table * update snapshot * update snapshot * fix lint * fix style lint * fix style * update snapshot * update desc * fix missing icon
137 lines
2.6 KiB
Markdown
137 lines
2.6 KiB
Markdown
---
|
|
order: 15
|
|
title:
|
|
en-US: colSpan and rowSpan
|
|
zh-CN: 表格行/列合并
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
表头只支持列合并,使用 column 里的 colSpan 进行设置。
|
|
|
|
表格支持行/列合并,使用 render 里的单元格属性 colSpan 或者 rowSpan 设值为 0 时,设置的表格不会渲染。
|
|
|
|
## 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.
|
|
|
|
```jsx
|
|
import { Table } from 'antd';
|
|
|
|
// In the fifth row, other columns are merged into first column
|
|
// by setting it's colSpan to be 0
|
|
const renderContent = (value, row, index) => {
|
|
const obj = {
|
|
children: value,
|
|
props: {},
|
|
};
|
|
if (index === 4) {
|
|
obj.props.colSpan = 0;
|
|
}
|
|
return obj;
|
|
};
|
|
|
|
const columns = [
|
|
{
|
|
title: 'Name',
|
|
dataIndex: 'name',
|
|
render: (text, row, index) => {
|
|
if (index < 4) {
|
|
return <a>{text}</a>;
|
|
}
|
|
return {
|
|
children: <a>{text}</a>,
|
|
props: {
|
|
colSpan: 5,
|
|
},
|
|
};
|
|
},
|
|
},
|
|
{
|
|
title: 'Age',
|
|
dataIndex: 'age',
|
|
render: renderContent,
|
|
},
|
|
{
|
|
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,
|
|
},
|
|
];
|
|
|
|
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',
|
|
},
|
|
];
|
|
|
|
ReactDOM.render(<Table columns={columns} dataSource={data} bordered />, mountNode);
|
|
```
|