2019-04-18 10:50:38 +08:00
|
|
|
/**
|
|
|
|
* @title 层级树大数据场景
|
|
|
|
* @parent 无限滚动 Infinite-scroll
|
|
|
|
* @description
|
2019-04-23 20:11:38 +08:00
|
|
|
* demo1404
|
2019-04-18 10:50:38 +08:00
|
|
|
*/
|
2018-12-18 13:59:48 +08:00
|
|
|
import React, { Component } from "react";
|
2019-11-06 15:03:26 +08:00
|
|
|
import { Button } from "tinper-bee";
|
2019-03-20 17:44:05 +08:00
|
|
|
|
2018-12-18 13:59:48 +08:00
|
|
|
import Table from "../../src";
|
|
|
|
import BigData from "../../src/lib/bigData";
|
|
|
|
const BigDataTable = BigData(Table);
|
2019-01-22 11:05:42 +08:00
|
|
|
const columns = [
|
|
|
|
{
|
2019-11-06 15:03:26 +08:00
|
|
|
title: '序号',
|
|
|
|
dataIndex: 'index',
|
|
|
|
width: '150',
|
|
|
|
key: 'index',
|
|
|
|
render: (text, record, index) => {
|
2019-09-11 21:08:18 +08:00
|
|
|
return record.index ? record.index : index
|
2019-02-26 17:06:52 +08:00
|
|
|
}
|
2019-01-22 11:05:42 +08:00
|
|
|
},
|
2019-11-06 15:03:26 +08:00
|
|
|
{ title: "用户名", dataIndex: "a", key: "a", width: 580, className: "rowClassName" },
|
|
|
|
{ id: "123", title: "性别", dataIndex: "b", key: "b", width: 80 },
|
2019-09-11 21:08:18 +08:00
|
|
|
{ title: "年龄", dataIndex: "c", key: "c", width: 200 }
|
2019-01-22 11:05:42 +08:00
|
|
|
];
|
2018-12-18 13:59:48 +08:00
|
|
|
|
2019-11-06 15:03:26 +08:00
|
|
|
const data = [...new Array(10)].map((e, i) => {
|
|
|
|
const rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', key: i };
|
|
|
|
if (i % 3 == 0) {
|
|
|
|
rs.b = '女';
|
|
|
|
rs.children = [];
|
|
|
|
for (let subi = 0; subi < 3; subi++) {
|
|
|
|
rs.children.push({ a: i + subi + 'asub', b: i + subi + 'bsub', c: i + subi + 'csub', d: i + subi + 'dsub', key: i + `${subi} sub` });
|
|
|
|
rs.children[subi].children = []
|
|
|
|
for (let subj = 0; subj < 100; subj++) {
|
|
|
|
rs.children[subi].children.push({ a: 333 + ' ' + subj, b: 333 + ' ' + subj, c: 333 + ' ' + subj, d: 333 + ' ' + subj, key: i + `${subj} sub1` });
|
|
|
|
}
|
2019-03-20 17:44:05 +08:00
|
|
|
}
|
2019-11-06 15:03:26 +08:00
|
|
|
} else {
|
|
|
|
rs.children = [];
|
|
|
|
for (let subi = 0; subi < 3; subi++) {
|
|
|
|
rs.children.push({ a: i + subi + 'asub', b: i + subi + 'bsub', c: i + subi + 'csub', d: i + subi + 'dsub', key: i + `${subi} sub` });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rs;
|
2019-09-11 21:08:18 +08:00
|
|
|
})
|
2018-12-18 13:59:48 +08:00
|
|
|
|
2019-11-06 15:03:26 +08:00
|
|
|
const data2 = [...new Array(10000)].map((e, i) => {
|
|
|
|
const rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', key: i };
|
|
|
|
if (i % 3 == 0) {
|
|
|
|
rs.b = '女';
|
|
|
|
}
|
|
|
|
return rs;
|
2019-09-11 21:08:18 +08:00
|
|
|
})
|
2018-12-18 13:59:48 +08:00
|
|
|
|
2019-03-20 17:44:05 +08:00
|
|
|
class Demo34 extends Component {
|
2019-11-06 15:03:26 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2019-11-12 15:22:24 +08:00
|
|
|
data: data
|
2019-11-06 15:03:26 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-12 15:22:24 +08:00
|
|
|
|
2019-11-06 15:03:26 +08:00
|
|
|
/**
|
|
|
|
* expanded : 当前的状态
|
|
|
|
* record : 当前行的数据
|
|
|
|
*/
|
|
|
|
onExpand = (expanded, record) => {
|
|
|
|
console.log('当前的状态---' + expanded, ' 当前行的数据---' , record);
|
|
|
|
}
|
|
|
|
handleClick = () => {
|
|
|
|
this.setState({
|
|
|
|
data: data2
|
|
|
|
})
|
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Button onClick={this.handleClick} colors="secondary" style={{ marginBottom: '8px' }}>改变数据源</Button>
|
|
|
|
<BigDataTable
|
|
|
|
columns={columns}
|
|
|
|
data={this.state.data}
|
|
|
|
parentNodeId='parent'
|
|
|
|
scroll={{ y: 300 }}
|
|
|
|
onExpand={this.onExpand}
|
|
|
|
onRowClick={(record, index, indent) => {
|
|
|
|
console.log('currentIndex--' + index);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-01-22 11:05:42 +08:00
|
|
|
|
2019-11-06 15:03:26 +08:00
|
|
|
);
|
2018-12-18 13:59:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:26:27 +08:00
|
|
|
export default Demo34;
|