Commit 8e171de8e02146eadee15de380922763a75d538d
1 parent
224a79e7
fixed #3124
Showing
2 changed files
with
15 additions
and
6 deletions
Show diff stats
src/components/table/table.vue
| ... | ... | @@ -23,12 +23,12 @@ |
| 23 | 23 | :obj-data="objData"></table-body> |
| 24 | 24 | </div> |
| 25 | 25 | <div |
| 26 | - :class="[prefixCls + '-tip']" | |
| 26 | + :class="[prefixCls + '-tip']" :style="bodyStyle" @scroll="handleBodyScroll" | |
| 27 | 27 | v-show="((!!localeNoDataText && (!data || data.length === 0)) || (!!localeNoFilteredDataText && (!rebuildData || rebuildData.length === 0)))"> |
| 28 | 28 | <table cellspacing="0" cellpadding="0" border="0"> |
| 29 | 29 | <tbody> |
| 30 | 30 | <tr> |
| 31 | - <td :style="{ 'height': bodyStyle.height }"> | |
| 31 | + <td :style="{'height':bodyStyle.height,'width':`${this.headerWidth}px`}"> | |
| 32 | 32 | <span v-html="localeNoDataText" v-if="!data || data.length === 0"></span> |
| 33 | 33 | <span v-html="localeNoFilteredDataText" v-else></span> |
| 34 | 34 | </td> |
| ... | ... | @@ -188,6 +188,7 @@ |
| 188 | 188 | currentContext: this.context, |
| 189 | 189 | cloneData: deepCopy(this.data), // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data |
| 190 | 190 | showVerticalScrollBar:false, |
| 191 | + headerWidth:0 | |
| 191 | 192 | }; |
| 192 | 193 | }, |
| 193 | 194 | computed: { |
| ... | ... | @@ -253,7 +254,7 @@ |
| 253 | 254 | if (this.bodyHeight > this.bodyRealHeight) { |
| 254 | 255 | width = this.tableWidth; |
| 255 | 256 | } else { |
| 256 | - width = this.tableWidth - this.scrollBarWidth; | |
| 257 | + width = this.tableWidth - (this.showVerticalScrollBar?this.scrollBarWidth:0); | |
| 257 | 258 | } |
| 258 | 259 | } |
| 259 | 260 | // const width = this.bodyHeight === 0 ? this.tableWidth : this.tableWidth - this.scrollBarWidth; |
| ... | ... | @@ -348,7 +349,12 @@ |
| 348 | 349 | this.tableWidth = parseInt(getStyle(this.$el, 'width')) - 1; |
| 349 | 350 | } |
| 350 | 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 | 358 | this.$nextTick(() => { |
| 353 | 359 | let columnsWidth = {}; |
| 354 | 360 | let autoWidthIndex = -1; |
| ... | ... | @@ -358,7 +364,6 @@ |
| 358 | 364 | const $tr = this.$refs.tbody.$el.querySelectorAll('tbody tr'); |
| 359 | 365 | if ($tr.length === 0) return; |
| 360 | 366 | const $td = $tr[0].children; |
| 361 | - | |
| 362 | 367 | for (let i = 0; i < $td.length; i++) { // can not use forEach in Firefox |
| 363 | 368 | const column = this.cloneColumns[i]; |
| 364 | 369 | |
| ... | ... | @@ -375,7 +380,6 @@ |
| 375 | 380 | }; |
| 376 | 381 | } |
| 377 | 382 | this.columnsWidth = columnsWidth; |
| 378 | - this.fixedHeader(); | |
| 379 | 383 | |
| 380 | 384 | if (this.$refs.tbody) { |
| 381 | 385 | let bodyContentEl = this.$refs.tbody.$el; | ... | ... |
src/styles/components/table.less