From 64270806474dc7cb94128d25e2d03405864c3fc5 Mon Sep 17 00:00:00 2001 From: jonyshi Date: Wed, 26 Jun 2019 16:18:39 +0800 Subject: [PATCH] =?UTF-8?q?=20=E8=A7=A3=E5=86=B3NCC=E6=8F=90=E5=87=BA?= =?UTF-8?q?=E7=9A=84=E6=8B=96=E5=8A=A8=E5=88=97=E5=AE=BD=E6=97=B6,?= =?UTF-8?q?=E6=9C=89=E5=9B=BA=E5=AE=9A=E5=88=97=E5=87=BA=E7=8E=B0=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E4=B8=AD=E9=97=B4=E6=96=AD=E5=BC=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TableHeader.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/TableHeader.js b/src/TableHeader.js index c8fc4de..2b57e53 100644 --- a/src/TableHeader.js +++ b/src/TableHeader.js @@ -31,6 +31,7 @@ class TableHeader extends Component { this.table = null; this._thead = null;//当前对象 this.event = false;//避免多次绑定问题 + this.lastColumWidth = null;//非固定列最后一列的初始化宽度 } static defaultProps = { @@ -185,7 +186,7 @@ class TableHeader extends Component { Event.stopPropagation(e); let event = Event.getEvent(e) , targetEvent = Event.getTarget(event); - const { clsPrefix, contentTable } = this.props; + const { clsPrefix, contentTable,lastShowIndex } = this.props; let currentElement = this.getOnLineObject(targetEvent); if(!currentElement)return; let type = currentElement.getAttribute('data-type'); @@ -202,6 +203,14 @@ class TableHeader extends Component { this.drag.oldWidth = parseInt((currentObj).style.width); this.drag.minWidth = currentObj.style.minWidth != ""?parseInt(currentObj.style.minWidth):defaultWidth; this.drag.tableWidth = parseInt(this.table.table.style.width ?this.table.table.style.width:this.table.table.scrollWidth); + console.log(" ----- ",this.drag); + if(!this.tableOldWidth){ + this.tableOldWidth = this.drag.tableWidth;//this.getTableWidth(); + // console.log(" this.tableOldWidth--- ",this.tableOldWidth); + } + if(!this.lastColumWidth){ + this.lastColumWidth = parseInt(this.table.cols[lastShowIndex].style.width); + } }else if(type != 'online' && this.props.draggable){ // if (!this.props.draggable || targetEvent.nodeName.toUpperCase() != "TH") return; if (!this.props.draggable) return; @@ -217,6 +226,15 @@ class TableHeader extends Component { } }; + getTableWidth = ()=>{ + let tableWidth = 0,offWidth = 0;//this.table.cols.length; + for (let index = 0; index < this.table.cols.length; index++) { + let da = this.table.cols[index]; + tableWidth += parseInt((da).style.width); + } + return (tableWidth-offWidth); + } + /** * 判断当前的target 是否是 th,如果不是,直接递归查找。 * @memberof TableHeader @@ -235,7 +253,7 @@ class TableHeader extends Component { */ onTrMouseMove = (e) => { if(!this.props.dragborder && !this.props.draggable)return; - const { clsPrefix ,dragborder,contentDomWidth,scrollbarWidth,contentTable,headerScroll} = this.props; + const { clsPrefix ,dragborder,contentDomWidth,scrollbarWidth,contentTable,headerScroll,lastShowIndex} = this.props; Event.stopPropagation(e); let event = Event.getEvent(e); if(this.props.dragborder && this.drag.option == "border"){ @@ -252,13 +270,20 @@ class TableHeader extends Component { if(this.fixedTable.cols){ this.fixedTable.cols[this.drag.currIndex].style.width = newWidth + "px"; } - const newTableWidth = this.drag.tableWidth + diff +'px'; - this.table.table.style.width = newTableWidth;//改变table的width - if(this.table.innerTableBody){//TODO 后续需要处理此处 - this.table.innerTableBody.style.width = newTableWidth ; + + // const newTableWidth = this.drag.tableWidth + diff;// +'px'; + // this.table.table.style.width = newTableWidth+'px';;//改变table的width + // if(this.table.innerTableBody){//TODO 后续需要处理此处 + // this.table.innerTableBody.style.width = newTableWidth+'px'; ; + // } + + let newDiff = (parseInt(currentCols.style.minWidth) - parseInt(currentCols.style.width)); + if(newDiff > 0){//缩小 + let lastWidth = this.lastColumWidth + newDiff; + this.table.cols[lastShowIndex].style.width = lastWidth +"px"; } + let showScroll = contentDomWidth - (this.drag.tableWidth + diff) - scrollbarWidth ; - //表头滚动条处理 if(headerScroll){ if(showScroll < 0){