2019-04-19 15:46:04 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @title 自定义行、列合并
|
|
|
|
|
* @parent 扩展行 Expanded Row
|
|
|
|
|
* @description 表头只支持列合并,使用 column 里的 colSpan 进行设置。表格支持行/列合并,使用 render 里的单元格属性 colSpan 或者 rowSpan 设值为 0 时,设置的表格不会渲染。
|
2019-04-23 20:11:38 +08:00
|
|
|
|
* demo1108
|
2019-04-19 15:46:04 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React, { Component } from "react";
|
2019-05-28 11:44:48 +08:00
|
|
|
|
import Button from 'bee-button';
|
2019-04-19 15:46:04 +08:00
|
|
|
|
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 = [{
|
2019-05-06 11:17:40 +08:00
|
|
|
|
title: '姓名',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
}, {
|
2019-05-06 11:17:40 +08:00
|
|
|
|
title: '年龄',
|
|
|
|
|
key: "age",
|
2019-04-19 15:46:04 +08:00
|
|
|
|
dataIndex: 'age',
|
|
|
|
|
render: renderContent,
|
|
|
|
|
}, {
|
2019-05-06 11:17:40 +08:00
|
|
|
|
title: '联系方式',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
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;
|
|
|
|
|
},
|
|
|
|
|
}, {
|
2019-05-06 11:17:40 +08:00
|
|
|
|
title: '手机号',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
colSpan: 0,
|
|
|
|
|
key: "phone",
|
|
|
|
|
dataIndex: 'phone',
|
|
|
|
|
render: renderContent,
|
|
|
|
|
}, {
|
2019-05-06 11:17:40 +08:00
|
|
|
|
title: '家庭住址',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
key: "address",
|
|
|
|
|
dataIndex: 'address',
|
|
|
|
|
render: renderContent,
|
|
|
|
|
}];
|
|
|
|
|
|
2019-05-27 10:16:46 +08:00
|
|
|
|
|
|
|
|
|
const columns1 = [{
|
|
|
|
|
title: '姓名',
|
|
|
|
|
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: '年龄',
|
|
|
|
|
key: "age",
|
|
|
|
|
dataIndex: 'age',
|
|
|
|
|
render: renderContent,
|
|
|
|
|
}, {
|
|
|
|
|
title: '联系方式',
|
|
|
|
|
colSpan: 2,
|
|
|
|
|
key: "tel",
|
|
|
|
|
dataIndex: 'tel',
|
|
|
|
|
render: renderContent
|
|
|
|
|
}, {
|
|
|
|
|
title: '手机号',
|
|
|
|
|
colSpan: 0,
|
|
|
|
|
key: "phone",
|
|
|
|
|
dataIndex: 'phone',
|
|
|
|
|
render: renderContent,
|
|
|
|
|
}, {
|
|
|
|
|
title: '家庭住址',
|
|
|
|
|
key: "address",
|
|
|
|
|
dataIndex: 'address',
|
|
|
|
|
render: renderContent,
|
|
|
|
|
}];
|
2019-04-19 15:46:04 +08:00
|
|
|
|
const data = [{
|
|
|
|
|
key: '1',
|
2019-05-06 11:17:40 +08:00
|
|
|
|
name: '小红',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
age: 32,
|
|
|
|
|
tel: '0571-22098909',
|
|
|
|
|
phone: 18889898989,
|
2019-05-06 11:17:40 +08:00
|
|
|
|
address: '北京海淀',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: '2',
|
2019-05-06 11:17:40 +08:00
|
|
|
|
name: '小明',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
tel: '0571-22098333',
|
|
|
|
|
phone: 18889898888,
|
|
|
|
|
age: 42,
|
2019-05-06 11:17:40 +08:00
|
|
|
|
address: '河北张家口',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: '3',
|
2019-05-06 11:17:40 +08:00
|
|
|
|
name: '张三',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
age: 32,
|
|
|
|
|
tel: '0575-22098909',
|
|
|
|
|
phone: 18900010002,
|
2019-05-06 11:17:40 +08:00
|
|
|
|
address: '浙江杭州',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: '4',
|
2019-05-06 11:17:40 +08:00
|
|
|
|
name: '李四',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
age: 18,
|
|
|
|
|
tel: '0575-22098909',
|
|
|
|
|
phone: 18900010002,
|
2019-05-06 11:17:40 +08:00
|
|
|
|
address: '广州深圳',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: '5',
|
2019-05-06 11:17:40 +08:00
|
|
|
|
name: '王五',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
age: 18,
|
|
|
|
|
tel: '0575-22098909',
|
|
|
|
|
phone: 18900010002,
|
2019-05-06 11:17:40 +08:00
|
|
|
|
address: '北京昌平',
|
2019-04-19 15:46:04 +08:00
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
class Demo15 extends Component {
|
2019-05-27 10:16:46 +08:00
|
|
|
|
constructor(props){
|
|
|
|
|
super(props);
|
|
|
|
|
this.state={
|
|
|
|
|
colFlag:false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onChange=()=>{
|
|
|
|
|
const colFlag = this.state.colFlag;
|
|
|
|
|
this.setState({
|
|
|
|
|
colFlag:!colFlag
|
|
|
|
|
})
|
|
|
|
|
}
|
2019-04-19 15:46:04 +08:00
|
|
|
|
render() {
|
2019-05-27 10:16:46 +08:00
|
|
|
|
let cols = this.state.colFlag?columns:columns1;
|
2019-04-19 15:46:04 +08:00
|
|
|
|
return (
|
2019-05-27 10:16:46 +08:00
|
|
|
|
<div>
|
2019-05-28 11:44:48 +08:00
|
|
|
|
<Button onClick={this.onChange} colors="secondary" style={{marginBottom:'8px'}}>change列</Button>
|
|
|
|
|
<Table columns={cols} data={data} bordered/>
|
2019-05-27 10:16:46 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
2019-04-19 15:46:04 +08:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default Demo15;
|