bee-table/demo/demolist/Demo1101.js

110 lines
3.2 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
* @description 通过expandedRowRender参数来实现子表格收起和展开的图标可自定义传入注意多选功能和嵌套表格一起使用时需要设置 expandIconAsCell={true}把展开按钮放在单元格中展示
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,Icon,Checkbox } from 'tinper-bee';
2018-12-21 09:58:52 +08:00
import Table from "../../src";
import multiSelect from "../../src/lib/multiSelect";
2019-07-03 21:12:17 +08:00
2019-03-20 17:44:05 +08:00
const columns16 = [
{
title: "操作",
dataIndex: "d",
key: "d",
width:100,
2019-03-20 17:44:05 +08:00
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, fixed:'right' },
2019-03-20 17:44:05 +08:00
];
const columns17 = [
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
];
const MultiSelectTable = multiSelect(Table,Checkbox);
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) => {
return (
<Table
columns={columns17}
data={this.state.data_obj[record.key]}
2019-03-20 17:44:05 +08:00
/>
);
};
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
})
}
}
}
2019-03-20 17:44:05 +08:00
haveExpandIcon=(record, index)=>{
//控制是否显示行展开icon该参数只有在和expandedRowRender同时使用才生效
if(index == 0){
return true;
}
return false;
2018-12-21 09:58:52 +08:00
}
2018-12-21 09:58:52 +08:00
render() {
return (
<MultiSelectTable
2019-07-03 21:12:17 +08:00
className="expanded-table"
2019-03-20 17:44:05 +08:00
columns={columns16}
data={data16}
onExpand={this.getData}
expandedRowRender={this.expandedRowRender}
expandIconAsCell={true}
2019-05-10 13:50:51 +08:00
collapsedIcon={<Icon type='uf-anglearrowpointingtoright'/>}
expandedIcon={<Icon type='uf-treearrow-down'/>}
2019-03-20 17:44:05 +08:00
/>
2018-12-21 09:58:52 +08:00
);
}
}
2019-03-20 17:44:05 +08:00
export default Demo16;