From 1c5c94238be884107e1aef2b39aa6999712411c0 Mon Sep 17 00:00:00 2001 From: wanghaoo Date: Sun, 2 Dec 2018 16:15:01 +0800 Subject: [PATCH] =?UTF-8?q?TableHeader=E6=8B=96=E6=8B=BD=E6=97=B6=20?= =?UTF-8?q?=E6=A8=AA=E5=90=91=E6=BB=9A=E5=8A=A8=E6=9D=A1=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TableHeader.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/TableHeader.js b/src/TableHeader.js index 8d6f4eb..94c15b3 100644 --- a/src/TableHeader.js +++ b/src/TableHeader.js @@ -153,7 +153,7 @@ class TableHeader extends Component { //---拖拽列宽代码逻辑----start----- onLineMouseMove = (e) => { - const { clsPrefix ,dragborder} = this.props; + const { clsPrefix ,dragborder,contentDomWidth,scrollbarWidth,contentTable,headerScroll} = this.props; Event.stopPropagation(e); let event = Event.getEvent(e); if (!this.props.dragborder) return; @@ -166,11 +166,39 @@ class TableHeader extends Component { let newWidth = this.drag.oldWidth + diff; if(newWidth > this.drag.minWidth){ currentCols.style.width = newWidth +'px'; - //hao 修改表体的width - this.fixedTable.cols[this.drag.currIndex].style.width = newWidth + "px"; + //hao 支持固定表头拖拽 修改表体的width + if(this.fixedTable.cols){ + this.fixedTable.cols[this.drag.currIndex].style.width = newWidth + "px"; + } + + //表头滚动条处理 + if(headerScroll){ + let oldTableWidth = parseInt(this.table.table.style.width ?this.table.table.style.width:this.table.table.scrollWidth); + const newTableWidth = oldTableWidth + diff ; + this.table.table.style.width = newTableWidth;//改变table的width + + let showScroll = contentDomWidth - newTableWidth - scrollbarWidth ; + // if(bordered){ + // showScroll = showScroll -1; + // } + const fixedLeftHeaderTable = contentTable.querySelector('.u-table-fixed-left .u-table-header') ; + const fixedRighHeadertTable = contentTable.querySelector('.u-table-fixed-right .u-table-header'); + const contentTableHeader = contentTable.querySelector('.u-table-scroll .u-table-header'); + if(showScroll < 0){ + //找到固定列表格,设置表头的marginBottom值为scrollbarWidth; + contentTableHeader.style.overflowX = 'scroll'; + fixedLeftHeaderTable && (fixedLeftHeaderTable.style.marginBottom = scrollbarWidth + "px"); + fixedRighHeadertTable && (fixedRighHeadertTable.style.marginBottom = scrollbarWidth + "px"); + }else{ + contentTableHeader.style.overflowX = 'hidden'; + fixedLeftHeaderTable && (fixedLeftHeaderTable.style.marginBottom = '0px'); + fixedRighHeadertTable && (fixedRighHeadertTable.style.marginBottom = '0px'); + } + } + } - //hao todo - this.table.table.style.width = (parseInt(this.table.table.style.width) + diff);//改变table的width + + }; onLineMouseDown = (e) => {