2018-12-21 09:58:52 +08:00
|
|
|
|
/**
|
2019-03-20 17:44:05 +08:00
|
|
|
|
*
|
2019-04-19 15:46:04 +08:00
|
|
|
|
* @title 树型表格数据展示
|
2019-04-18 10:50:38 +08:00
|
|
|
|
* @parent 扩展行 Expanded Row
|
2019-03-20 17:44:05 +08:00
|
|
|
|
* @description 通过在data中配置children数据,来自动生成树形表格
|
2019-04-23 20:11:38 +08:00
|
|
|
|
* demo1102
|
2019-03-20 17:44:05 +08:00
|
|
|
|
*/
|
2018-12-21 09:58:52 +08:00
|
|
|
|
|
|
|
|
|
|
2019-03-20 17:44:05 +08:00
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import Table from '../../src';
|
2018-12-21 09:58:52 +08:00
|
|
|
|
|
|
|
|
|
|
2019-03-20 17:44:05 +08:00
|
|
|
|
const columns4 = [
|
2018-12-21 09:58:52 +08:00
|
|
|
|
{
|
2019-04-24 14:15:59 +08:00
|
|
|
|
title: "订单编号",
|
2019-03-20 17:44:05 +08:00
|
|
|
|
dataIndex: "name",
|
|
|
|
|
key: "name",
|
|
|
|
|
width: "40%"
|
2018-12-21 09:58:52 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-04-24 14:15:59 +08:00
|
|
|
|
title: "单据日期",
|
2019-03-20 17:44:05 +08:00
|
|
|
|
dataIndex: "age",
|
|
|
|
|
key: "age",
|
|
|
|
|
width: "30%"
|
2018-12-21 09:58:52 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2019-04-24 14:15:59 +08:00
|
|
|
|
title: "供应商",
|
2019-03-20 17:44:05 +08:00
|
|
|
|
dataIndex: "address",
|
|
|
|
|
key: "address"
|
2018-12-21 09:58:52 +08:00
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2019-03-20 17:44:05 +08:00
|
|
|
|
const data4 = [
|
|
|
|
|
{
|
|
|
|
|
key: 1,
|
2019-04-24 14:15:59 +08:00
|
|
|
|
name: "NU0391001",
|
|
|
|
|
age: "2019-03-01",
|
|
|
|
|
address: "供应商1",
|
2019-03-20 17:44:05 +08:00
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
key: 11,
|
2019-04-24 14:15:59 +08:00
|
|
|
|
name: "NU0391002",
|
|
|
|
|
age: "2019-03-02",
|
|
|
|
|
address: "供应商2"
|
2019-03-20 17:44:05 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 12,
|
2019-04-24 14:15:59 +08:00
|
|
|
|
name: "NU0391003",
|
|
|
|
|
age: "2019-03-03",
|
|
|
|
|
address: "供应商3",
|
2019-03-20 17:44:05 +08:00
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
key: 121,
|
2019-04-24 14:15:59 +08:00
|
|
|
|
name: "NU0391004",
|
|
|
|
|
age: "2019-03-04",
|
|
|
|
|
address: "供应商4"
|
2019-03-20 17:44:05 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 13,
|
2019-04-24 14:15:59 +08:00
|
|
|
|
name: "NU0391005",
|
|
|
|
|
age: "2019-03-05",
|
|
|
|
|
address: "供应商5",
|
2019-03-20 17:44:05 +08:00
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
key: 131,
|
2019-04-24 14:15:59 +08:00
|
|
|
|
name: "NU0391006",
|
|
|
|
|
age: "2019-03-06",
|
|
|
|
|
address: "供应商6",
|
2019-03-20 17:44:05 +08:00
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
key: 1311,
|
2019-04-24 14:15:59 +08:00
|
|
|
|
name: "NU0391007",
|
|
|
|
|
age: "2019-03-07",
|
|
|
|
|
address: "供应商7"
|
2019-03-20 17:44:05 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 1312,
|
2019-04-24 14:15:59 +08:00
|
|
|
|
name: "NU0391008",
|
|
|
|
|
age: "2019-03-08",
|
|
|
|
|
address: "供应商8"
|
2019-03-20 17:44:05 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 2,
|
2019-04-24 14:15:59 +08:00
|
|
|
|
name: "NU0391009",
|
|
|
|
|
age: "2019-03-09",
|
|
|
|
|
address: "供应商9"
|
2019-03-20 17:44:05 +08:00
|
|
|
|
}
|
2018-12-21 09:58:52 +08:00
|
|
|
|
];
|
2019-03-20 17:44:05 +08:00
|
|
|
|
class Demo4 extends Component {
|
|
|
|
|
|
|
|
|
|
constructor(props){
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
data: data4,
|
|
|
|
|
factoryValue: 0,
|
|
|
|
|
selectedRow: new Array(data4.length)//状态同步
|
|
|
|
|
}
|
2018-12-21 09:58:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-03-20 17:44:05 +08:00
|
|
|
|
return <Table
|
|
|
|
|
rowClassName={(record,index,indent)=>{
|
|
|
|
|
if (this.state.selectedRow[index]) {
|
|
|
|
|
return 'selected';
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
onRowClick={(record,index,indent)=>{
|
|
|
|
|
let selectedRow = new Array(this.state.data.length);
|
|
|
|
|
selectedRow[index] = true;
|
|
|
|
|
this.setState({
|
|
|
|
|
factoryValue: record,
|
|
|
|
|
selectedRow: selectedRow
|
|
|
|
|
});
|
|
|
|
|
}}
|
2020-04-01 14:54:41 +08:00
|
|
|
|
rowKey="key"//每条数据的唯一标示,默认为key,如果不是key,必须传
|
2019-03-20 17:44:05 +08:00
|
|
|
|
columns={columns4} data={data4} />;
|
2018-12-21 09:58:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:44:05 +08:00
|
|
|
|
|
|
|
|
|
export default Demo4;
|