fix: 改用key来判断currentRecord

This commit is contained in:
gx 2021-04-30 14:32:24 +08:00
parent 3016f23f31
commit b81dcbc3ef
7 changed files with 28 additions and 36 deletions

View File

@ -1747,7 +1747,7 @@ var Table = function (_Component) {
var isTreeType = this.isTreeType;
var record = isTreeType ? propsRecord : lazyLoad ? data.find(function (item) {
return item.originIndex === currentIndex;
return item.key === key;
}) : data[currentIndex];
// 固定列、或者含有hoverdom时情况下同步hover状态
if (this.columnManager.isAnyColumnsFixed() && syncHover) {
@ -1777,7 +1777,6 @@ var Table = function (_Component) {
});
}
}
onRowHover && onRowHover(currentIndex, record);
};

View File

@ -79,7 +79,7 @@ function bigData(Table) {
var currentIndex = nextProps.currentIndex,
newExpandedKeys = nextProps.expandedRowKeys;
var newData = this.modifyNewData(nextProps.data);
var newData = nextProps.data;
var _this = this,
dataLen = newData.length;
if (nextProps.scroll.y !== props.scroll.y) {
@ -387,14 +387,6 @@ function bigData(Table) {
}, _initialiseProps = function _initialiseProps() {
var _this5 = this;
this.modifyNewData = function (data) {
if (!data && !data.length) return data;
return data.map(function (item, index) {
item.originIndex = index;
return item;
});
};
this.getTreeData = function (expandedKeys, newData) {
var startIndex = _this5.startIndex,
endIndex = _this5.endIndex;

34
dist/demo.js vendored
View File

@ -48260,6 +48260,7 @@
_this.columnManager = new _ColumnManager2['default'](props.columns, props.children, props.originWidth, showDragHandle, props.showRowNum); // 加入props.showRowNum参数
_this.store = (0, _createStore2['default'])({ currentHoverKey: null });
_this.firstDid = true;
_this.scrollYChanged = false;
if (props.defaultExpandAllRows) {
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
@ -48424,6 +48425,7 @@
this.bodyTable.scrollTop = 0;
} else if (this.props.ignoreScrollYChange && currentScrollY && prevScrollY) {
if (prevScrollY !== currentScrollY) {
this.scrollYChanged = true;
var bodyScrollTop = this.bodyTable.scrollTop;
if (bodyScrollTop === 0) {
// 在顶部的时候,滚动条不用动
@ -48446,17 +48448,15 @@
}
}
}
} else {
} else if (this.scrollYChanged) {
this.bodyTable.scrollTop += 1;
this.scrollYChanged = false;
}
}
// 是否传入 scroll中的y属性如果传入判断是否是整数如果是则进行比较 。bodyTable 的clientHeight进行判断
this.isShowScrollY();
if (this.bodyTable) {
var currentOverflowX = window.getComputedStyle(this.bodyTable).overflowX;
if (!this.props.scroll.x && currentOverflowX === 'scroll') {
this.bodyTable.style.overflowX = 'hidden';
}
if (this.props.scroll.x && currentOverflowX !== 'scroll') {
// 此处应该对比一下实际的
if (this.computeWidth > this.contentDomWidth) {
@ -48464,6 +48464,14 @@
}
}
}
var scrollContainerWidth = window.getComputedStyle(this.bodyTableOuter.querySelector('.scroll-container')).width; // scroll-container层元素的宽度
var scrollContainerTableWidth = this.bodyTableOuter.querySelector('.table-bordered').style.width; // scroll-container内层table元素的宽度
// 有左右固定列时scroll-container因为有竖直滚动条使得scroll-container实际宽度不包括滚动条的宽度小于内部table宽度出现水平方向滚动条导致滚动到底部不对齐
if (parseFloat(scrollContainerWidth) >= parseFloat(scrollContainerTableWidth) && (this.columnManager.leftLeafColumns().length > 0 || this.columnManager.rightLeafColumns().length > 0)) {
this.bodyTable.style.overflowX = 'hidden';
} else {
this.bodyTable.style.overflowX = 'auto';
}
if (this.bodyTableOuter) {
// 隐藏几个不需要真正滚动的父元素的滚动条
this.bodyTableOuter.style.overflowY = 'hidden';
@ -49210,9 +49218,10 @@
} else {
if (this.computeWidth > this.contentDomWidth) {
bodyStyle.marginBottom = '-' + scrollbarWidth + 'px';
var userAgent = navigator.userAgent; // 火狐浏览器固定表格跟随resize事件产生的滚动条隐藏
var userAgent = navigator.userAgent; // 火狐IE浏览器固定表格跟随resize事件产生的滚动条隐藏
var isFF = userAgent.indexOf("Firefox") > -1;
if (isFF) {
var isIE = !!window.ActiveXObject || "ActiveXObject" in window;
if (isFF || isIE) {
// innerBodyStyle.overflowX = 'hidden';
delete innerBodyStyle.overflowX;
}
@ -49640,12 +49649,15 @@
var _props11 = this.props,
syncHover = _props11.syncHover,
onRowHover = _props11.onRowHover,
data = _props11.data;
data = _props11.data,
lazyLoad = _props11.lazyLoad;
//fix:树形表onRowHover返回参数异常
var isTreeType = this.isTreeType;
var record = isTreeType ? propsRecord : data[currentIndex];
var record = isTreeType ? propsRecord : lazyLoad ? data.find(function (item) {
return item.key === key;
}) : data[currentIndex];
// 固定列、或者含有hoverdom时情况下同步hover状态
if (this.columnManager.isAnyColumnsFixed() && syncHover) {
this.hoverKey = key;
@ -49674,7 +49686,6 @@
});
}
}
onRowHover && onRowHover(currentIndex, record);
};
@ -49729,7 +49740,6 @@
if (hasFixedLeft) {
className += ' has-fixed-left';
}
return _react2['default'].createElement(
'div',
{ className: className, style: props.style, ref: function ref(el) {
@ -49767,7 +49777,7 @@
onMouseEnter: this.onRowHoverMouseEnter, onMouseLeave: this.onRowHoverMouseLeave, ref: function ref(el) {
return _this7.hoverDom = el;
} },
props.hoverContent(currentHoverRecord, currentHoverIndex)
currentHoverRecord ? props.hoverContent(currentHoverRecord, currentHoverIndex) : null
)
);
};
@ -309221,9 +309231,9 @@
BigData.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
var props = this.props;
var currentIndex = nextProps.currentIndex,
newData = nextProps.data,
newExpandedKeys = nextProps.expandedRowKeys;
var newData = nextProps.data;
var _this = this,
dataLen = newData.length;
if (nextProps.scroll.y !== props.scroll.y) {

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "bee-table",
"version": "2.3.15-beta.27",
"version": "2.3.15-beta.28",
"description": "Table ui component for react",
"keywords": [
"react",

View File

@ -1502,7 +1502,7 @@ class Table extends Component {
let { syncHover,onRowHover,data, lazyLoad } = this.props;
//fix:树形表onRowHover返回参数异常
let { isTreeType } = this;
const record = isTreeType ? propsRecord : lazyLoad ? data.find(item => item.originIndex === currentIndex) : data[currentIndex];
const record = isTreeType ? propsRecord : lazyLoad ? data.find(item => item.key === key) : data[currentIndex];
// 固定列、或者含有hoverdom时情况下同步hover状态
if(this.columnManager.isAnyColumnsFixed() && syncHover ){
this.hoverKey = key;
@ -1531,7 +1531,6 @@ class Table extends Component {
})
}
}
onRowHover && onRowHover(currentIndex,record);
}

View File

@ -51,7 +51,7 @@ export default function bigData(Table) {
componentWillReceiveProps(nextProps) {
const props = this.props;
const {currentIndex, expandedRowKeys:newExpandedKeys} = nextProps;
const newData = this.modifyNewData(nextProps.data)
const newData = nextProps.data
const _this = this,dataLen = newData.length;
if (nextProps.scroll.y !== props.scroll.y) {
const rowHeight = nextProps.height ? nextProps.height : defaultHeight;
@ -108,14 +108,6 @@ export default function bigData(Table) {
}
}
modifyNewData = data => {
if (!data && !data.length) return data
return data.map((item, index) => {
item.originIndex = index
return item
})
}
/**
* 如果是树形表需要对传入的 data 进行处理
* @param expandedKeys: nextProps 中传入的新 expandedRowKeys 属性值