Commit 8e171de8e02146eadee15de380922763a75d538d

Authored by huanghong
1 parent 224a79e7

fixed #3124

src/components/table/table.vue
@@ -23,12 +23,12 @@ @@ -23,12 +23,12 @@
23 :obj-data="objData"></table-body> 23 :obj-data="objData"></table-body>
24 </div> 24 </div>
25 <div 25 <div
26 - :class="[prefixCls + '-tip']" 26 + :class="[prefixCls + '-tip']" :style="bodyStyle" @scroll="handleBodyScroll"
27 v-show="((!!localeNoDataText && (!data || data.length === 0)) || (!!localeNoFilteredDataText && (!rebuildData || rebuildData.length === 0)))"> 27 v-show="((!!localeNoDataText && (!data || data.length === 0)) || (!!localeNoFilteredDataText && (!rebuildData || rebuildData.length === 0)))">
28 <table cellspacing="0" cellpadding="0" border="0"> 28 <table cellspacing="0" cellpadding="0" border="0">
29 <tbody> 29 <tbody>
30 <tr> 30 <tr>
31 - <td :style="{ 'height': bodyStyle.height }"> 31 + <td :style="{'height':bodyStyle.height,'width':`${this.headerWidth}px`}">
32 <span v-html="localeNoDataText" v-if="!data || data.length === 0"></span> 32 <span v-html="localeNoDataText" v-if="!data || data.length === 0"></span>
33 <span v-html="localeNoFilteredDataText" v-else></span> 33 <span v-html="localeNoFilteredDataText" v-else></span>
34 </td> 34 </td>
@@ -188,6 +188,7 @@ @@ -188,6 +188,7 @@
188 currentContext: this.context, 188 currentContext: this.context,
189 cloneData: deepCopy(this.data), // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data 189 cloneData: deepCopy(this.data), // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data
190 showVerticalScrollBar:false, 190 showVerticalScrollBar:false,
  191 + headerWidth:0
191 }; 192 };
192 }, 193 },
193 computed: { 194 computed: {
@@ -253,7 +254,7 @@ @@ -253,7 +254,7 @@
253 if (this.bodyHeight > this.bodyRealHeight) { 254 if (this.bodyHeight > this.bodyRealHeight) {
254 width = this.tableWidth; 255 width = this.tableWidth;
255 } else { 256 } else {
256 - width = this.tableWidth - this.scrollBarWidth; 257 + width = this.tableWidth - (this.showVerticalScrollBar?this.scrollBarWidth:0);
257 } 258 }
258 } 259 }
259 // const width = this.bodyHeight === 0 ? this.tableWidth : this.tableWidth - this.scrollBarWidth; 260 // const width = this.bodyHeight === 0 ? this.tableWidth : this.tableWidth - this.scrollBarWidth;
@@ -348,7 +349,12 @@ @@ -348,7 +349,12 @@
348 this.tableWidth = parseInt(getStyle(this.$el, 'width')) - 1; 349 this.tableWidth = parseInt(getStyle(this.$el, 'width')) - 1;
349 } 350 }
350 this.columnsWidth = {}; 351 this.columnsWidth = {};
351 - if (!this.$refs.tbody) return; 352 + this.fixedHeader();
  353 + this.headerWidth = this.$refs.header.childNodes[0].offsetWidth;
  354 + if (!this.$refs.tbody) {
  355 + this.showVerticalScrollBar = false;
  356 + return;
  357 + }
352 this.$nextTick(() => { 358 this.$nextTick(() => {
353 let columnsWidth = {}; 359 let columnsWidth = {};
354 let autoWidthIndex = -1; 360 let autoWidthIndex = -1;
@@ -358,7 +364,6 @@ @@ -358,7 +364,6 @@
358 const $tr = this.$refs.tbody.$el.querySelectorAll('tbody tr'); 364 const $tr = this.$refs.tbody.$el.querySelectorAll('tbody tr');
359 if ($tr.length === 0) return; 365 if ($tr.length === 0) return;
360 const $td = $tr[0].children; 366 const $td = $tr[0].children;
361 -  
362 for (let i = 0; i < $td.length; i++) { // can not use forEach in Firefox 367 for (let i = 0; i < $td.length; i++) { // can not use forEach in Firefox
363 const column = this.cloneColumns[i]; 368 const column = this.cloneColumns[i];
364 369
@@ -375,7 +380,6 @@ @@ -375,7 +380,6 @@
375 }; 380 };
376 } 381 }
377 this.columnsWidth = columnsWidth; 382 this.columnsWidth = columnsWidth;
378 - this.fixedHeader();  
379 383
380 if (this.$refs.tbody) { 384 if (this.$refs.tbody) {
381 let bodyContentEl = this.$refs.tbody.$el; 385 let bodyContentEl = this.$refs.tbody.$el;
src/styles/components/table.less
@@ -74,6 +74,11 @@ @@ -74,6 +74,11 @@
74 overflow: auto; 74 overflow: auto;
75 //position: relative; 75 //position: relative;
76 } 76 }
  77 + &-tip{
  78 + overflow-x: auto;
  79 + overflow-y: hidden;
  80 + //position: relative;
  81 + }
77 82
78 &-with-fixed-top&-with-footer{ 83 &-with-fixed-top&-with-footer{
79 .@{table-prefix-cls}-footer{ 84 .@{table-prefix-cls}-footer{