From 6e4a08be896fcadc066afe60b9a358e9b2aea4e3 Mon Sep 17 00:00:00 2001 From: wanghaoo Date: Mon, 12 Nov 2018 17:50:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=A1=A8=E6=A0=BC=E5=90=88=E8=AE=A1?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=81=E5=A4=9A=E8=A1=A8=E5=A4=B4headerHei?= =?UTF-8?q?ght=E9=97=AE=E9=A2=98):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/Table.js | 18 ++++++++++++++---- build/lib/sum.js | 27 +++++++++++++++------------ build/utils.js | 1 - package.json | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/build/Table.js b/build/Table.js index 2ab29a0..96609bf 100644 --- a/build/Table.js +++ b/build/Table.js @@ -278,6 +278,9 @@ var Table = function (_Component) { //如果用户传了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') { var numSetWidthParam = parseInt(setWidthParam); this.contentWidth = numSetWidthParam; @@ -287,13 +290,12 @@ var Table = function (_Component) { this.contentDomWidth = this.contentTable.getBoundingClientRect().width; //表格容器宽度 this.contentWidth = this.contentDomWidth; //默认与容器宽度一样 + this.domWidthDiff = this.contentDomWidth - this.computeWidth; if (typeof setWidthParam == 'string' && setWidthParam.indexOf('%')) { 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) { var contentWidthDiff = this.scrollbarWidth ? this.contentWidth - this.computeWidth - this.scrollbarWidth : this.contentWidth - this.computeWidth; //bordered的表格需要减去边框的差值1 @@ -761,7 +763,15 @@ var Table = function (_Component) { headStyle.marginBottom = '0px'; } } 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'; + } } } } diff --git a/build/lib/sum.js b/build/lib/sum.js index 738595c..dc2c912 100644 --- a/build/lib/sum.js +++ b/build/lib/sum.js @@ -43,26 +43,29 @@ function sum(Table) { _this.currentFooter = function () { var data_2 = _this.props.data; 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++) { if (columns_sum[i].sumCol) { - sumCol_index = columns_sum[i].dataIndex; - break; + sumColIndexArr.push(columns_sum[i].dataIndex); } } var obj = {}; - obj[sumCol_index] = 0; - if (Array.isArray(data_2)) { - for (var _i = 0; _i < data_2.length; _i++) { - if (typeof data_2[_i][sumCol_index] == "number" || !isNaN(data_2[_i][sumCol_index])) { - obj[sumCol_index] -= -data_2[_i][sumCol_index]; - } else { - obj[sumCol_index] = ""; + sumColIndexArr.forEach(function (sumCol_index) { + + obj[sumCol_index] = 0; + if (Array.isArray(data_2)) { + for (var _i = 0; _i < data_2.length; _i++) { + if (typeof data_2[_i][sumCol_index] == "number" || !isNaN(data_2[_i][sumCol_index])) { + obj[sumCol_index] -= -data_2[_i][sumCol_index]; + } else { + obj[sumCol_index] = ""; + } } } - } - obj.key = "sumData"; + obj.key = sumCol_index + "sumData"; + }); obj.showSum = "合计"; obj = [obj]; //将设置的和用户传入的合并属性 diff --git a/build/utils.js b/build/utils.js index ffb21e6..1f6f0e6 100644 --- a/build/utils.js +++ b/build/utils.js @@ -185,6 +185,5 @@ function getColChildrenLength(columns, chilrenLen) { chilrenLen = getColChildrenLength(item.children, chilrenLen + 1); } }); - console.log(chilrenLen); return chilrenLen; } \ No newline at end of file diff --git a/package.json b/package.json index 9a63eb7..b7123e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bee-table", - "version": "1.4.37", + "version": "1.4.38", "description": "Table ui component for react", "keywords": [ "react",