curentIndex修改

This commit is contained in:
wanghaoo 2019-01-25 11:17:52 +08:00
parent 54d5ccf359
commit a19aba657a
6 changed files with 93 additions and 125 deletions

View File

@ -310,14 +310,17 @@ function bigData(Table) {
onExpand: function onExpand() {},
scroll: {},
currentIndex: -1
currentIndex: -1,
isTree: false
}, _class.propTypes = {
loadBuffer: _propTypes2["default"].number
}, _initialiseProps = function _initialiseProps() {
var _this4 = this;
this.computeCachedRowParentIndex = function (data) {
var isTreeType = _this4.checkIsTreeType();
var isTree = _this4.props.isTree;
var isTreeType = isTree ? true : _this4.checkIsTreeType();
if (isTreeType) {
data.forEach(function (item, index) {
_this4.firstLevelKey[index] = _this4.getRowKey(item, index);

File diff suppressed because one or more lines are too long

181
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

@ -183,7 +183,7 @@ class Table extends Component {
this.columnManager.reset(null, nextProps.children);
}
//适配lazyload
if(nextProps.scrollTop){
if(nextProps.scrollTop > -1){
// this.refs.bodyTable.scrollTop = nextProps.scrollTop;
this.scrollTop = nextProps.scrollTop;
}
@ -206,11 +206,11 @@ class Table extends Component {
this.computeTableWidth();
this.firstDid = false;//避免重复update
}
if(this.scrollTop){
if(this.scrollTop > -1){
this.refs.fixedColumnsBodyLeft && ( this.refs.fixedColumnsBodyLeft.scrollTop = this.scrollTop);
this.refs.fixedColumnsBodyRight && ( this.refs.fixedColumnsBodyRight.scrollTop = this.scrollTop);
this.refs.bodyTable.scrollTop = this.scrollTop;
this.scrollTop = 0;
this.scrollTop = -1;
}

View File

@ -1,6 +1,6 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
const defaultHeight = 40;
const defaultHeight = 30;
const rowDiff = 3; //行差值
let treeTypeIndex = 0;
export default function bigData(Table) {
@ -11,7 +11,8 @@ export default function bigData(Table) {
rowKey: "key",
onExpand() {},
scroll: {},
currentIndex:-1
currentIndex:-1,
isTree:false
};
static propTypes = {
loadBuffer: PropTypes.number
@ -79,7 +80,8 @@ export default function bigData(Table) {
*
*/
computeCachedRowParentIndex = data => {
const isTreeType = this.checkIsTreeType();
const {isTree} = this.props;
const isTreeType = isTree?true:this.checkIsTreeType();
if (isTreeType) {
data.forEach((item, index) => {
this.firstLevelKey[index] = this.getRowKey(item, index);
@ -96,7 +98,7 @@ export default function bigData(Table) {
setStartAndEndIndex(currentIndex,dataLen){
const _this = this;
if(currentIndex > _this.endIndex){
if(currentIndex > _this.currentIndex + _this.props.rowsInView){
_this.currentIndex = currentIndex;
_this.endIndex = _this.currentIndex; //数据开始位置
_this.startIndex = _this.currentIndex - _this.loadCount; //数据结束位置
@ -106,7 +108,9 @@ export default function bigData(Table) {
if(_this.startIndex < 0){
_this.startIndex = 0;
}
}else if(currentIndex < _this.startIndex){
//重新设定scrollTop值
_this.scrollTop = _this.getSumHeight(0, _this.endIndex - _this.rowsInView +2);
}else if(currentIndex < _this.currentIndex){
_this.currentIndex = currentIndex;
_this.startIndex = currentIndex;
_this.endIndex = currentIndex + _this.loadCount;
@ -116,10 +120,10 @@ export default function bigData(Table) {
if(_this.startIndex < 0){
_this.startIndex = 0;
}
}
//重新设定scrollTop值
_this.scrollTop = _this.getSumHeight(0, _this.endIndex - _this.rowsInView +2);
_this.scrollTop = _this.getSumHeight(0, _this.startIndex);
}
}
getRowKey(record, index) {