124 lines
2.3 KiB
JavaScript
124 lines
2.3 KiB
JavaScript
/**
|
|
*
|
|
* @title 自定义行、列合并
|
|
* @parent 扩展行 Expanded Row
|
|
* @description 表头只支持列合并,使用 column 里的 colSpan 进行设置。表格支持行/列合并,使用 render 里的单元格属性 colSpan 或者 rowSpan 设值为 0 时,设置的表格不会渲染。
|
|
* demo1108
|
|
*/
|
|
|
|
import React, { Component } from "react";
|
|
import Table from "../../src";
|
|
|
|
const renderContent = (value, row, index) => {
|
|
const obj = {
|
|
children: value,
|
|
props: {},
|
|
};
|
|
if (index === 4) {
|
|
obj.props.colSpan = 0;
|
|
}
|
|
return obj;
|
|
};
|
|
|
|
const columns = [{
|
|
title: 'Name',
|
|
key: "name",
|
|
dataIndex: 'name',
|
|
render: (text, row, index) => {
|
|
if (index < 4) {
|
|
return <a href="#">{text}</a>;
|
|
}
|
|
return {
|
|
children: <a href="#">{text}</a>,
|
|
props: {
|
|
colSpan: 5,
|
|
},
|
|
};
|
|
},
|
|
}, {
|
|
title: 'Age',
|
|
key: "Age",
|
|
dataIndex: 'age',
|
|
render: renderContent,
|
|
}, {
|
|
title: 'Home phone',
|
|
colSpan: 2,
|
|
key: "tel",
|
|
dataIndex: 'tel',
|
|
render: (value, row, index) => {
|
|
const obj = {
|
|
children: value,
|
|
props: {},
|
|
};
|
|
if (index === 2) {
|
|
obj.props.rowSpan = 2;
|
|
}
|
|
if (index === 3) {
|
|
obj.props.rowSpan = 0;
|
|
}
|
|
if (index === 4) {
|
|
obj.props.colSpan = 0;
|
|
}
|
|
return obj;
|
|
},
|
|
}, {
|
|
title: 'Phone',
|
|
colSpan: 0,
|
|
key: "phone",
|
|
dataIndex: 'phone',
|
|
render: renderContent,
|
|
}, {
|
|
title: 'Address',
|
|
key: "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',
|
|
}];
|
|
|
|
class Demo15 extends Component {
|
|
render() {
|
|
return (
|
|
<Table columns={columns} data={data} bordered/>
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
export default Demo15;
|