大数据在expandedRow下的场景

This commit is contained in:
wanghaoo 2018-12-18 18:14:09 +08:00
parent 6fa264e5b9
commit b2017909ae
10 changed files with 78 additions and 64 deletions

View File

@ -68,7 +68,16 @@ class Demo31 extends Component {
constructor(props){ constructor(props){
super(props); super(props);
this.state={ this.state={
data_obj:{} data_obj:{
0:[
{ a: "令狐冲", b: "男", c: 41, d: "操作", key: "1" },
{ a: "杨过", b: "男", c: 67, d: "操作", key: "2" }
],
1: [
{ a: "令狐冲", b: "男", c: 41, d: "操作", key: "1" },
{ a: "菲菲", b: "nv", c: 67, d: "操作", key: "2" }
],
}
} }
} }
expandedRowRender = (record, index, indent) => { expandedRowRender = (record, index, indent) => {
@ -121,6 +130,7 @@ class Demo31 extends Component {
onExpand={this.getData} onExpand={this.getData}
expandedRowRender={this.expandedRowRender} expandedRowRender={this.expandedRowRender}
scroll={{y:350}} scroll={{y:350}}
defaultExpandedRowKeys={[0,1]}
title={currentData => <div>标题: 这是一个标题</div>} title={currentData => <div>标题: 这是一个标题</div>}
footer={currentData => <div>表尾: 我是小尾巴</div>} footer={currentData => <div>表尾: 我是小尾巴</div>}
/> />

File diff suppressed because one or more lines are too long

4
dist/demo.css vendored
View File

@ -8417,7 +8417,6 @@ ul {
.u-table { .u-table {
font-size: 12px; font-size: 12px;
color: #666; color: #666;
transition: opacity 0.3s ease;
position: relative; position: relative;
line-height: 1.5; line-height: 1.5;
overflow: hidden; } overflow: hidden; }
@ -8435,8 +8434,7 @@ ul {
border-collapse: collapse; border-collapse: collapse;
text-align: left; } text-align: left; }
.u-table th { .u-table th {
font-weight: bold; font-weight: bold; }
transition: background 0.3s ease; }
.u-table th[colspan] { .u-table th[colspan] {
text-align: center; } text-align: center; }
.u-table th ::last-child { .u-table th ::last-child {

2
dist/demo.css.map vendored

File diff suppressed because one or more lines are too long

68
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -579,6 +579,7 @@ class Table extends Component {
fixed={fixed} fixed={fixed}
lazyCurrentIndex={lazyCurrentIndex} lazyCurrentIndex={lazyCurrentIndex}
expandedContentHeight={expandedContentHeight} expandedContentHeight={expandedContentHeight}
setRowHeight={props.setRowHeight}
/> />
); );
this.treeRowIndex++; this.treeRowIndex++;

View File

@ -17,7 +17,7 @@ $checkbox-height:16px;
.u-table { .u-table {
font-size: $font-size-base; font-size: $font-size-base;
color: $text-color; color: $text-color;
transition: opacity 0.3s ease; // transition: opacity 0.3s ease;
position: relative; position: relative;
line-height: $line-height; line-height: $line-height;
overflow: hidden; overflow: hidden;
@ -43,7 +43,7 @@ $checkbox-height:16px;
th { th {
// background: $table-head-background-color; // background: $table-head-background-color;
font-weight: bold; font-weight: bold;
transition: background 0.3s ease; // transition: background 0.3s ease;
&[colspan] { &[colspan] {
text-align: center; text-align: center;
} }

View File

@ -68,6 +68,12 @@ class TableRow extends Component{
this.setRowHeight() this.setRowHeight()
} }
componentDidUpdate(prevProps) {
if (this.props.index !== prevProps.index) {
this.setRowHeight()
}
}
componentWillUnmount() { componentWillUnmount() {
const { record, onDestroy, index } = this.props; const { record, onDestroy, index } = this.props;
onDestroy(record, index); onDestroy(record, index);
@ -78,9 +84,9 @@ class TableRow extends Component{
setRowHeight() { setRowHeight() {
const { setRowHeight , expandedContentHeight} = this.props const { setRowHeight , expandedContentHeight,lazyCurrentIndex=0,fixed} = this.props
if (!setRowHeight || !this.element) return if (!setRowHeight || !this.element || fixed) return
setRowHeight(this.element.clientHeight + expandedContentHeight, this.props.index) setRowHeight(this.element.clientHeight + expandedContentHeight, this.props.index+lazyCurrentIndex)
} }
onRowClick(event) { onRowClick(event) {

View File

@ -19,9 +19,12 @@ export default function bigData(Table) {
scrollTop: 0 scrollTop: 0
}; };
const rowHeight = this.props.height?this.props.height:defaultHeight const rowHeight = this.props.height?this.props.height:defaultHeight
//默认显示25条rowsInView根据定高算的。在非固定高下这个只是一个大概的值。
this.rowsInView = this.props.scroll.y?Math.ceil(this.props.scroll.y/rowHeight):25 ; this.rowsInView = this.props.scroll.y?Math.ceil(this.props.scroll.y/rowHeight):25 ;
this.cachedRowHeight = []; this.cachedRowHeight = [];
this.lastScrollTop = 0; this.lastScrollTop = 0;
this.setRowHeight = this.setRowHeight.bind(this);
} }
/** /**
*获取数据区高度 *获取数据区高度
@ -43,16 +46,16 @@ export default function bigData(Table) {
return sumHeight; return sumHeight;
} }
getIndex(scrollTop = this.state.scrollTop) { // getIndex(scrollTop = this.state.scrollTop) {
const { data } = this.props // const { data } = this.props
const {rowsInView} = this; // const {rowsInView} = this;
const max = data.length // const max = data.length
const mcf = scrollTop > 0.5 ? Math.ceil : Math.floor // const mcf = scrollTop > 0.5 ? Math.ceil : Math.floor
let index = mcf((scrollTop * max) - (rowsInView * scrollTop)) // let index = mcf((scrollTop * max) - (rowsInView * scrollTop))
if (index > max - rowsInView) index = max - rowsInView // if (index > max - rowsInView) index = max - rowsInView
if (index < 0) index = 0 // if (index < 0) index = 0
return index // return index
} // }
// getLastRowHeight = (index) =>{ // getLastRowHeight = (index) =>{
@ -91,20 +94,12 @@ export default function bigData(Table) {
if(currentIndex !== index){ if(currentIndex !== index){
this.setState({ currentIndex: index ,scrollTop:scrollTop}) this.setState({ currentIndex: index ,scrollTop:scrollTop})
} }
// this.lastScrollTop = scrollTop;
//scrollTop/rowHeight如果小于0.5按当前值如果大于0.5为下一个currentIndex 值
} }
setRowHeight(height, index) { setRowHeight(height, index) {
const oldHeight = this.cachedRowHeight[index]
this.cachedRowHeight[index] = height this.cachedRowHeight[index] = height
const rowHeight = this.props.height?this.props.height:defaultHeight; }
let { currentIndex ,scrollTop} = this.state
if (currentIndex === index && !oldHeight) {
scrollTop += height - rowHeight;
}
this.setState({scrollTop});
}
render() { render() {
const { data } = this.props; const { data } = this.props;
const { currentIndex,scrollTop } = this.state; const { currentIndex,scrollTop } = this.state;