fix: update时判断表格数据

This commit is contained in:
izbz wh 2020-12-15 20:55:48 +08:00
parent 7558e57018
commit 9e7b9f763d
6 changed files with 19 additions and 16 deletions

View File

@ -459,7 +459,7 @@ var Table = function (_Component) {
Table.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { Table.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
// todo: IE 大数据渲染,行高不固定,且设置了 heightConsistent={true} 时,滚动加载操作会导致 ie11 浏览器崩溃 // todo: IE 大数据渲染,行高不固定,且设置了 heightConsistent={true} 时,滚动加载操作会导致 ie11 浏览器崩溃
// https://github.com/tinper-bee/bee-table/commit/bd2092cdbaad236ff89477304e58dea93325bf09 // https://github.com/tinper-bee/bee-table/commit/bd2092cdbaad236ff89477304e58dea93325bf09
if (this.columnManager.isAnyColumnsFixed()) { if (this.columnManager.isAnyColumnsFixed() && !prevProps.height && prevProps.data == this.props.data) {
this.syncFixedTableRowHeight(); this.syncFixedTableRowHeight();
} }
@ -1437,7 +1437,7 @@ var Table = function (_Component) {
if (headerHeight) { if (headerHeight) {
height = ((0, _utils.getMaxColChildrenLength)(columns) + 1) * headerHeight; height = ((0, _utils.getMaxColChildrenLength)(columns) + 1) * headerHeight;
} }
return headerHeight ? height : row.getBoundingClientRect().height || 'auto'; return headerHeight ? height : parseInt(row.getBoundingClientRect().height) || 'auto';
}); });
var fixedColumnsBodyRowsHeight = [].map.call(bodyRows, function (row, index) { var fixedColumnsBodyRowsHeight = [].map.call(bodyRows, function (row, index) {
var rsHeight = height; var rsHeight = height;
@ -1451,13 +1451,13 @@ var Table = function (_Component) {
rightHeight = void 0, rightHeight = void 0,
currentHeight = void 0, currentHeight = void 0,
maxHeight = void 0; maxHeight = void 0;
leftHeight = leftBodyRows[index] ? leftBodyRows[index].getBoundingClientRect().height : 0; leftHeight = leftBodyRows[index] ? parseInt(leftBodyRows[index].getBoundingClientRect().height) : 0;
rightHeight = rightBodyRows[index] ? rightBodyRows[index].getBoundingClientRect().height : 0; rightHeight = rightBodyRows[index] ? parseInt(rightBodyRows[index].getBoundingClientRect().height) : 0;
currentHeight = row.getBoundingClientRect().height; currentHeight = parseInt(row.getBoundingClientRect().height);
maxHeight = Math.max(leftHeight, rightHeight, currentHeight); maxHeight = Math.max(leftHeight, rightHeight, currentHeight);
return maxHeight || 'auto'; return maxHeight || 'auto';
} else { } else {
return row.getBoundingClientRect().height || 'auto'; return parseInt(row.getBoundingClientRect().height) || 'auto';
} }
} }
}); });
@ -1465,19 +1465,20 @@ var Table = function (_Component) {
// expandedRows为NodeList Array.prototype.forEach ie 下报错 对象不支持 “forEach” 方法 // expandedRows为NodeList Array.prototype.forEach ie 下报错 对象不支持 “forEach” 方法
expandedRows.length > 0 && Array.prototype.forEach.call(expandedRows, function (row) { expandedRows.length > 0 && Array.prototype.forEach.call(expandedRows, function (row) {
var parentRowKey = row && row.previousSibling && row.previousSibling.getAttribute("data-row-key"), var parentRowKey = row && row.previousSibling && row.previousSibling.getAttribute("data-row-key"),
height = row && row.getBoundingClientRect().height || 'auto'; height = row && parseInt(row.getBoundingClientRect().height) || 'auto';
try { try {
//子表数据减少时,动态计算高度 //子表数据减少时,动态计算高度
var td = row.querySelector('td'); var td = row.querySelector('td');
var tdPadding = _this5.getTdPadding(td); var tdPadding = _this5.getTdPadding(td);
var trueheight = row.querySelectorAll('.u-table')[0].getBoundingClientRect().height; var trueheight = parseInt(row.querySelectorAll('.u-table')[0].getBoundingClientRect().height);
height = trueheight + tdPadding; height = trueheight + tdPadding;
} catch (error) {} } catch (error) {}
fixedColumnsExpandedRowsHeight[parentRowKey] = height; fixedColumnsExpandedRowsHeight[parentRowKey] = parseInt(height);
}); });
if ((0, _shallowequal2["default"])(this.state.fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight) && (0, _shallowequal2["default"])(this.state.fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight) && (0, _shallowequal2["default"])(this.state.fixedColumnsExpandedRowsHeight, fixedColumnsExpandedRowsHeight)) { if ((0, _shallowequal2["default"])(this.state.fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight) && (0, _shallowequal2["default"])(this.state.fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight) && (0, _shallowequal2["default"])(this.state.fixedColumnsExpandedRowsHeight, fixedColumnsExpandedRowsHeight)) {
return; return;
} }
this.setState({ this.setState({
fixedColumnsHeadRowsHeight: fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight: fixedColumnsHeadRowsHeight,
fixedColumnsBodyRowsHeight: fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight: fixedColumnsBodyRowsHeight,

View File

@ -607,7 +607,7 @@ var _initialiseProps = function _initialiseProps() {
} }
var currentObj = _this8.table.cols[currentIndex]; var currentObj = _this8.table.cols[currentIndex];
_this8.drag.currIndex = currentIndex; _this8.drag.currIndex = currentIndex;
_this8.drag.oldLeft = event.x; _this8.drag.oldLeft = event.clientX;
_this8.drag.oldWidth = parseInt(currentObj.style.width); _this8.drag.oldWidth = parseInt(currentObj.style.width);
_this8.drag.minWidth = currentObj.style.minWidth != "" ? parseInt(currentObj.style.minWidth) : defaultWidth; _this8.drag.minWidth = currentObj.style.minWidth != "" ? parseInt(currentObj.style.minWidth) : defaultWidth;
_this8.drag.tableWidth = parseInt(_this8.table.table.style.width ? _this8.table.table.style.width : _this8.table.table.scrollWidth); _this8.drag.tableWidth = parseInt(_this8.table.table.style.width ? _this8.table.table.style.width : _this8.table.table.scrollWidth);
@ -680,7 +680,7 @@ var _initialiseProps = function _initialiseProps() {
if (_this8.props.dragborder && _this8.drag.option == "border") { if (_this8.props.dragborder && _this8.drag.option == "border") {
//移动改变宽度 //移动改变宽度
var currentCols = _this8.table.cols[_this8.drag.currIndex]; var currentCols = _this8.table.cols[_this8.drag.currIndex];
var diff = event.x - _this8.drag.oldLeft; var diff = event.clientX - _this8.drag.oldLeft;
var newWidth = _this8.drag.oldWidth + diff; var newWidth = _this8.drag.oldWidth + diff;
_this8.drag.newWidth = newWidth > 0 ? newWidth : _this8.minWidth; _this8.drag.newWidth = newWidth > 0 ? newWidth : _this8.minWidth;
if (newWidth > _this8.minWidth) { if (newWidth > _this8.minWidth) {

View File

@ -249,7 +249,8 @@ function sort(Table, Icon) {
this.multiSort = function (columns) { this.multiSort = function (columns) {
var _state = _this3.state, var _state = _this3.state,
data = _state.data, data = _state.data,
oldData = _state.oldData; _state$oldData = _state.oldData,
oldData = _state$oldData === undefined ? [] : _state$oldData;
var self = _this3; var self = _this3;
var orderCols = {}, var orderCols = {},
@ -274,7 +275,8 @@ function sort(Table, Icon) {
this.toggleSortOrder = function (order, column) { this.toggleSortOrder = function (order, column) {
var _state2 = _this3.state, var _state2 = _this3.state,
data = _state2.data, data = _state2.data,
oldData = _state2.oldData, _state2$oldData = _state2.oldData,
oldData = _state2$oldData === undefined ? [] : _state2$oldData,
flatColumns = _state2.flatColumns; flatColumns = _state2.flatColumns;
var sort = _this3.props.sort; var sort = _this3.props.sort;

2
dist/demo.js vendored
View File

@ -48143,7 +48143,7 @@
Table.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { Table.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
// todo: IE 大数据渲染,行高不固定,且设置了 heightConsistent={true} 时,滚动加载操作会导致 ie11 浏览器崩溃 // todo: IE 大数据渲染,行高不固定,且设置了 heightConsistent={true} 时,滚动加载操作会导致 ie11 浏览器崩溃
// https://github.com/tinper-bee/bee-table/commit/bd2092cdbaad236ff89477304e58dea93325bf09 // https://github.com/tinper-bee/bee-table/commit/bd2092cdbaad236ff89477304e58dea93325bf09
if (this.columnManager.isAnyColumnsFixed() && !prevProps.height) { if (this.columnManager.isAnyColumnsFixed() && !prevProps.height && prevProps.data == this.props.data) {
this.syncFixedTableRowHeight(); this.syncFixedTableRowHeight();
} }

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -251,7 +251,7 @@ class Table extends Component {
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
// todo: IE 大数据渲染,行高不固定,且设置了 heightConsistent={true} 时,滚动加载操作会导致 ie11 浏览器崩溃 // todo: IE 大数据渲染,行高不固定,且设置了 heightConsistent={true} 时,滚动加载操作会导致 ie11 浏览器崩溃
// https://github.com/tinper-bee/bee-table/commit/bd2092cdbaad236ff89477304e58dea93325bf09 // https://github.com/tinper-bee/bee-table/commit/bd2092cdbaad236ff89477304e58dea93325bf09
if(this.columnManager.isAnyColumnsFixed() && !prevProps.height) { if(this.columnManager.isAnyColumnsFixed() && !prevProps.height && prevProps.data == this.props.data) {
this.syncFixedTableRowHeight(); this.syncFixedTableRowHeight();
} }