fix(表格合计问题、多表头headerHeight问题):

This commit is contained in:
wanghaoo 2018-11-12 17:50:47 +08:00
parent 6784947b67
commit 6e4a08be89
4 changed files with 30 additions and 18 deletions

View File

@ -278,6 +278,9 @@ var Table = function (_Component) {
//如果用户传了scroll.x按用户传的为主 //如果用户传了scroll.x按用户传的为主
var setWidthParam = this.props.scroll.x; var setWidthParam = this.props.scroll.x;
var computeObj = this.columnManager.getColumnWidth(this.contentWidth);
var lastShowIndex = computeObj.lastShowIndex;
this.computeWidth = computeObj.computeWidth;
if (typeof setWidthParam == 'number') { if (typeof setWidthParam == 'number') {
var numSetWidthParam = parseInt(setWidthParam); var numSetWidthParam = parseInt(setWidthParam);
this.contentWidth = numSetWidthParam; this.contentWidth = numSetWidthParam;
@ -287,13 +290,12 @@ var Table = function (_Component) {
this.contentDomWidth = this.contentTable.getBoundingClientRect().width; //表格容器宽度 this.contentDomWidth = this.contentTable.getBoundingClientRect().width; //表格容器宽度
this.contentWidth = this.contentDomWidth; //默认与容器宽度一样 this.contentWidth = this.contentDomWidth; //默认与容器宽度一样
this.domWidthDiff = this.contentDomWidth - this.computeWidth;
if (typeof setWidthParam == 'string' && setWidthParam.indexOf('%')) { if (typeof setWidthParam == 'string' && setWidthParam.indexOf('%')) {
this.contentWidth = this.contentWidth * parseInt(setWidthParam) / 100; this.contentWidth = this.contentWidth * parseInt(setWidthParam) / 100;
} }
} }
var computeObj = this.columnManager.getColumnWidth(this.contentWidth);
var lastShowIndex = computeObj.lastShowIndex;
this.computeWidth = computeObj.computeWidth;
if (this.computeWidth < this.contentWidth) { if (this.computeWidth < this.contentWidth) {
var contentWidthDiff = this.scrollbarWidth ? this.contentWidth - this.computeWidth - this.scrollbarWidth : this.contentWidth - this.computeWidth; var contentWidthDiff = this.scrollbarWidth ? this.contentWidth - this.computeWidth - this.scrollbarWidth : this.contentWidth - this.computeWidth;
//bordered的表格需要减去边框的差值1 //bordered的表格需要减去边框的差值1
@ -761,7 +763,15 @@ var Table = function (_Component) {
headStyle.marginBottom = '0px'; headStyle.marginBottom = '0px';
} }
} else { } else {
(fixed ? bodyStyle : headStyle).marginBottom = '-' + scrollbarWidth + 'px'; if (fixed) {
if (this.domWidthDiff > 0) {
innerBodyStyle.overflowX = 'auto';
} else {
bodyStyle.marginBottom = '-' + scrollbarWidth + 'px';
}
} else {
headStyle.marginBottom = '-' + scrollbarWidth + 'px';
}
} }
} }
} }

View File

@ -43,26 +43,29 @@ function sum(Table) {
_this.currentFooter = function () { _this.currentFooter = function () {
var data_2 = _this.props.data; var data_2 = _this.props.data;
var columns_sum = _this.props.columns.concat(); var columns_sum = _this.props.columns.concat();
var sumCol_index = void 0; var sumCol_index = void 0,
sumColIndexArr = [];
//用一个对象存储合计数据,这里合计对象的属性对应每列字段 //用一个对象存储合计数据,这里合计对象的属性对应每列字段
for (var i = 0; i < columns_sum.length; i++) { for (var i = 0; i < columns_sum.length; i++) {
if (columns_sum[i].sumCol) { if (columns_sum[i].sumCol) {
sumCol_index = columns_sum[i].dataIndex; sumColIndexArr.push(columns_sum[i].dataIndex);
break;
} }
} }
var obj = {}; var obj = {};
obj[sumCol_index] = 0; sumColIndexArr.forEach(function (sumCol_index) {
if (Array.isArray(data_2)) {
for (var _i = 0; _i < data_2.length; _i++) { obj[sumCol_index] = 0;
if (typeof data_2[_i][sumCol_index] == "number" || !isNaN(data_2[_i][sumCol_index])) { if (Array.isArray(data_2)) {
obj[sumCol_index] -= -data_2[_i][sumCol_index]; for (var _i = 0; _i < data_2.length; _i++) {
} else { if (typeof data_2[_i][sumCol_index] == "number" || !isNaN(data_2[_i][sumCol_index])) {
obj[sumCol_index] = ""; obj[sumCol_index] -= -data_2[_i][sumCol_index];
} else {
obj[sumCol_index] = "";
}
} }
} }
} obj.key = sumCol_index + "sumData";
obj.key = "sumData"; });
obj.showSum = "合计"; obj.showSum = "合计";
obj = [obj]; obj = [obj];
//将设置的和用户传入的合并属性 //将设置的和用户传入的合并属性

View File

@ -185,6 +185,5 @@ function getColChildrenLength(columns, chilrenLen) {
chilrenLen = getColChildrenLength(item.children, chilrenLen + 1); chilrenLen = getColChildrenLength(item.children, chilrenLen + 1);
} }
}); });
console.log(chilrenLen);
return chilrenLen; return chilrenLen;
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "bee-table", "name": "bee-table",
"version": "1.4.37", "version": "1.4.38",
"description": "Table ui component for react", "description": "Table ui component for react",
"keywords": [ "keywords": [
"react", "react",