Skip to content

Commit

Permalink
fix: 嵌套表格兼容问题
Browse files Browse the repository at this point in the history
  • Loading branch information
whizbz11 committed Dec 1, 2020
1 parent 34e748e commit aaed13e
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 330 deletions.
2 changes: 1 addition & 1 deletion demo/index.js

Large diffs are not rendered by default.

626 changes: 307 additions & 319 deletions dist/demo.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/demo.js.map

Large diffs are not rendered by default.

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

Expand Down Expand Up @@ -1219,7 +1219,7 @@ class Table extends Component {
if(headerHeight){
height = (getMaxColChildrenLength(columns)+1)*headerHeight;
}
return headerHeight ? height : (row.getBoundingClientRect().height || 'auto')}
return headerHeight ? height : (parseInt(row.getBoundingClientRect().height) || 'auto')}
);
const fixedColumnsBodyRowsHeight = [].map.call(
bodyRows, (row,index) =>{
Expand All @@ -1231,13 +1231,13 @@ class Table extends Component {
// 内容折行显示,并又设置了 height 的情况下,也要获取主表高度
if(heightConsistent || (!bodyDisplayInRow && rsHeight)){
let leftHeight,rightHeight,currentHeight,maxHeight;
leftHeight = leftBodyRows[index]?leftBodyRows[index].getBoundingClientRect().height:0;
rightHeight = rightBodyRows[index]?rightBodyRows[index].getBoundingClientRect().height:0;
currentHeight = row.getBoundingClientRect().height
leftHeight = leftBodyRows[index]?parseInt(leftBodyRows[index].getBoundingClientRect().height):0;
rightHeight = rightBodyRows[index]?parseInt(rightBodyRows[index].getBoundingClientRect().height):0;
currentHeight = parseInt(row.getBoundingClientRect().height)
maxHeight = Math.max(leftHeight,rightHeight,currentHeight);
return maxHeight || 'auto'
}else{
return row.getBoundingClientRect().height || 'auto'
return parseInt(row.getBoundingClientRect().height) || 'auto'
}
}
}
Expand All @@ -1246,22 +1246,23 @@ class Table extends Component {
// expandedRows为NodeList Array.prototype.forEach ie 下报错 对象不支持 “forEach” 方法
expandedRows.length > 0 && Array.prototype.forEach.call(expandedRows,row => {
let parentRowKey = row && row.previousSibling && row.previousSibling.getAttribute("data-row-key"),
height = row && row.getBoundingClientRect().height || 'auto';
height = row && parseInt(row.getBoundingClientRect().height) || 'auto';
try {//子表数据减少时,动态计算高度
let td = row.querySelector('td');
let tdPadding = this.getTdPadding(td);
let trueheight = row.querySelectorAll('.u-table')[0].getBoundingClientRect().height;
let trueheight = parseInt(row.querySelectorAll('.u-table')[0].getBoundingClientRect().height);
height = trueheight+tdPadding;
} catch (error) {

}
fixedColumnsExpandedRowsHeight[parentRowKey] = height;
fixedColumnsExpandedRowsHeight[parentRowKey] = parseInt(height);
})
if (shallowequal(this.state.fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight) &&
shallowequal(this.state.fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight) &&
shallowequal(this.state.fixedColumnsExpandedRowsHeight, fixedColumnsExpandedRowsHeight)) {
return;
}

this.setState({
fixedColumnsHeadRowsHeight,
fixedColumnsBodyRowsHeight,
Expand Down

0 comments on commit aaed13e

Please sign in to comment.