bee-table7/demo/demolist/Demo1101.js

128 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-12-21 09:58:52 +08:00
/**
2019-03-20 17:44:05 +08:00
*
* @title 嵌套子表格
2019-04-18 10:50:38 +08:00
* @parent 扩展行 Expanded Row
2019-03-20 17:44:05 +08:00
* @description 通过expandedRowRender参数来实现子表格
2019-04-23 20:11:38 +08:00
* demo1101
2019-03-20 17:44:05 +08:00
*/
2018-12-21 09:58:52 +08:00
import React, { Component } from "react";
import { Popconfirm } from 'tinper-bee';
2018-12-21 09:58:52 +08:00
import Table from "../../src";
2019-03-20 17:44:05 +08:00
import dragColumn from '../../src/lib/dragColumn';
const DragColumnTable = dragColumn(Table);
const columns16 = [
{
title: "操作",
dataIndex: "d",
key: "d",
width:200,
render(text, record, index) {
return (
<Popconfirm trigger="click" placement="right" content={'这是第' + index + '行,内容为:' + text}>
<a href="javascript:;" tooltip={text} >
2019-03-20 17:44:05 +08:00
一些操作
</a>
</Popconfirm>
2019-03-20 17:44:05 +08:00
);
}
},
2019-04-24 14:15:59 +08:00
{ title: "订单编号", dataIndex: "a", key: "a", width: 250 },
{ id: "123", title: "单据日期", dataIndex: "b", key: "b", width: 100 },
{ title: "供应商", dataIndex: "c", key: "c", width: 200 },
2019-03-20 17:44:05 +08:00
];
const columns17 = [
2018-12-21 09:58:52 +08:00
{
2019-03-20 17:44:05 +08:00
title: "操作",
2018-12-21 09:58:52 +08:00
dataIndex: "d",
2019-03-20 17:44:05 +08:00
key: "d",
width:200,
render(text, record, index) {
return (
<Popconfirm trigger="click" placement="right" content={'这是第' + index + '行,内容为:' + text}>
<a href="javascript:;" tooltip={text} >
2019-03-20 17:44:05 +08:00
一些操作
</a>
</Popconfirm>
2019-03-20 17:44:05 +08:00
);
}
},
2019-04-24 14:15:59 +08:00
{ title: "订单编号", dataIndex: "a", key: "a", width: 100 },
{ id: "123", title: "单据日期", dataIndex: "b", key: "b", width: 100 },
{ title: "供应商", dataIndex: "c", key: "c", width: 200 },
2019-03-20 17:44:05 +08:00
];
const data16 = [
2019-04-24 14:15:59 +08:00
{ a: "NU0391001", b: "2019-03-01", c: "xx供应商", d: "操作", key: "1" },
{ a: "NU0391002", b: "2018-11-02", c: "yy供应商", d: "操作", key: "2" },
{ a: "NU0391003", b: "2019-05-03", c: "zz供应商", d: "操作", key: "3" }
2018-12-21 09:58:52 +08:00
];
2019-03-20 17:44:05 +08:00
class Demo16 extends Component {
constructor(props){
2018-12-21 09:58:52 +08:00
super(props);
2019-03-20 17:44:05 +08:00
this.state={
data_obj:{}
}
2018-12-21 09:58:52 +08:00
}
2019-03-20 17:44:05 +08:00
expandedRowRender = (record, index, indent) => {
let height = 42 * (this.state.data_obj[record.key].length+ 2);
return (
<Table
columns={columns17}
style={{height:height}}
data={this.state.data_obj[record.key]}
/>
);
};
getData=(expanded, record)=>{
//当点击展开的时候才去请求数据
let new_obj = Object.assign({},this.state.data_obj);
if(expanded){
if(record.key==='1'){
new_obj[record.key] = [
2019-04-24 14:15:59 +08:00
{ a: "NU0391056", b: "2019-03-01", c: "gys1", d: "操作", key: "1" },
{ a: "NU0391057", b: "2018-11-02", c: "gys2", d: "操作", key: "2" },
2019-03-20 17:44:05 +08:00
]
this.setState({
data_obj:new_obj
})
}else{
new_obj[record.key] = [
2019-04-24 14:15:59 +08:00
{ a: "NU0391079", b: "2019-04-17", c: "gys5", d: "操作", key: "3" },
2019-03-20 17:44:05 +08:00
]
this.setState({
data_obj:new_obj
})
}
}
}
haveExpandIcon=(record, index)=>{
//控制是否显示行展开icon该参数只有在和expandedRowRender同时使用才生效
if(index == 0){
return true;
}
return false;
2018-12-21 09:58:52 +08:00
}
render() {
return (
2019-03-20 17:44:05 +08:00
<DragColumnTable
columns={columns16}
data={data16}
onExpand={this.getData}
expandedRowRender={this.expandedRowRender}
scroll={{x:true}}
dragborder={true}
draggable={true}
/>
2018-12-21 09:58:52 +08:00
);
}
}
2019-03-20 17:44:05 +08:00
export default Demo16;