Commit 8744e122ee7ef851b2f9d231c8cbd45257fb20e7
Committed by
GitHub
Merge pull request #2 from huanghong1125/iss3124
Iss3124
Showing
4 changed files
with
156 additions
and
28 deletions
Show diff stats
examples/routers/table.vue
| ... | ... | @@ -5,7 +5,12 @@ |
| 5 | 5 | <Button @click="handleClearData">Clear Data</Button> |
| 6 | 6 | <Button @click="handleSelectAll(true)">Set all selected</Button> |
| 7 | 7 | <Button @click="handleSelectAll(false)">Cancel all selected</Button> |
| 8 | - | |
| 8 | + <div style='margin:20px 0px'> | |
| 9 | + <Table border :columns="columns2" :data="data3"></Table> | |
| 10 | + </div> | |
| 11 | + <div style='margin:20px 0px'> | |
| 12 | + <Table :height='200' border :columns="columns2" :data="data3"></Table> | |
| 13 | + </div> | |
| 9 | 14 | <div style='margin:20px 0px;'> |
| 10 | 15 | <Table :data="tableData1" :columns="tableColumns1" :height='500' stripe size='small'></Table> |
| 11 | 16 | <div style="margin: 10px;overflow: hidden"> |
| ... | ... | @@ -14,6 +19,7 @@ |
| 14 | 19 | </div> |
| 15 | 20 | </div> |
| 16 | 21 | </div> |
| 22 | + | |
| 17 | 23 | </div> |
| 18 | 24 | </template> |
| 19 | 25 | <script> |
| ... | ... | @@ -49,6 +55,95 @@ |
| 49 | 55 | data1: [ |
| 50 | 56 | |
| 51 | 57 | ], |
| 58 | + columns2: [ | |
| 59 | + { | |
| 60 | + title: 'Name', | |
| 61 | + key: 'name', | |
| 62 | + width: 100, | |
| 63 | + fixed: 'left' | |
| 64 | + }, | |
| 65 | + { | |
| 66 | + title: 'Age', | |
| 67 | + key: 'age', | |
| 68 | + width: 100 | |
| 69 | + }, | |
| 70 | + { | |
| 71 | + title: 'Province', | |
| 72 | + key: 'province', | |
| 73 | + width: 100 | |
| 74 | + }, | |
| 75 | + { | |
| 76 | + title: 'City', | |
| 77 | + key: 'city', | |
| 78 | + width: 100 | |
| 79 | + }, | |
| 80 | + { | |
| 81 | + title: 'Address', | |
| 82 | + key: 'address', | |
| 83 | + width: 200 | |
| 84 | + }, | |
| 85 | + { | |
| 86 | + title: 'Postcode', | |
| 87 | + key: 'zip', | |
| 88 | + width: 100 | |
| 89 | + }, | |
| 90 | + { | |
| 91 | + title: 'Action', | |
| 92 | + key: 'action', | |
| 93 | + fixed: 'right', | |
| 94 | + width: 120, | |
| 95 | + render: (h, params) => { | |
| 96 | + return h('div', [ | |
| 97 | + h('Button', { | |
| 98 | + props: { | |
| 99 | + type: 'text', | |
| 100 | + size: 'small' | |
| 101 | + } | |
| 102 | + }, 'View'), | |
| 103 | + h('Button', { | |
| 104 | + props: { | |
| 105 | + type: 'text', | |
| 106 | + size: 'small' | |
| 107 | + } | |
| 108 | + }, 'Edit') | |
| 109 | + ]); | |
| 110 | + } | |
| 111 | + } | |
| 112 | + ], | |
| 113 | + data3: [ | |
| 114 | + { | |
| 115 | + name: 'John Brown', | |
| 116 | + age: 18, | |
| 117 | + address: 'New York No. 1 Lake Park', | |
| 118 | + province: 'America', | |
| 119 | + city: 'New York', | |
| 120 | + zip: 100000 | |
| 121 | + }, | |
| 122 | + { | |
| 123 | + name: 'Jim Green', | |
| 124 | + age: 24, | |
| 125 | + address: 'Washington, D.C. No. 1 Lake Park', | |
| 126 | + province: 'America', | |
| 127 | + city: 'Washington, D.C.', | |
| 128 | + zip: 100000 | |
| 129 | + }, | |
| 130 | + { | |
| 131 | + name: 'Joe Black', | |
| 132 | + age: 30, | |
| 133 | + address: 'Sydney No. 1 Lake Park', | |
| 134 | + province: 'Australian', | |
| 135 | + city: 'Sydney', | |
| 136 | + zip: 100000 | |
| 137 | + }, | |
| 138 | + { | |
| 139 | + name: 'Jon Snow', | |
| 140 | + age: 26, | |
| 141 | + address: 'Ottawa No. 2 Lake Park', | |
| 142 | + province: 'Canada', | |
| 143 | + city: 'Ottawa', | |
| 144 | + zip: 100000 | |
| 145 | + } | |
| 146 | + ], | |
| 52 | 147 | |
| 53 | 148 | tableData1: [], |
| 54 | 149 | tableColumns1: [ | ... | ... |
src/components/table/mixin.js
| ... | ... | @@ -31,7 +31,7 @@ export default { |
| 31 | 31 | width += scrollBarWidth; |
| 32 | 32 | } |
| 33 | 33 | // when fixed type,reset first right fixed column's width |
| 34 | - if (this.fixed === 'right') { | |
| 34 | + if (this.fixed === 'right' && top ) { | |
| 35 | 35 | const firstFixedIndex = this.columns.findIndex((col) => col.fixed === 'right'); |
| 36 | 36 | if (firstFixedIndex === index) { |
| 37 | 37 | let scrollBarWidth = this.$parent.scrollBarWidth; | ... | ... |
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,8 @@ |
| 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 | + showHorizontalScrollBar:false, | |
| 192 | + headerWidth:0 | |
| 191 | 193 | }; |
| 192 | 194 | }, |
| 193 | 195 | computed: { |
| ... | ... | @@ -253,7 +255,7 @@ |
| 253 | 255 | if (this.bodyHeight > this.bodyRealHeight) { |
| 254 | 256 | width = this.tableWidth; |
| 255 | 257 | } else { |
| 256 | - width = this.tableWidth - this.scrollBarWidth; | |
| 258 | + width = this.tableWidth - (this.showVerticalScrollBar?this.scrollBarWidth:0); | |
| 257 | 259 | } |
| 258 | 260 | } |
| 259 | 261 | // const width = this.bodyHeight === 0 ? this.tableWidth : this.tableWidth - this.scrollBarWidth; |
| ... | ... | @@ -276,8 +278,9 @@ |
| 276 | 278 | this.rightFixedColumns.forEach((col) => { |
| 277 | 279 | if (col.fixed && col.fixed === 'right') width += col._width; |
| 278 | 280 | }); |
| 279 | - width += this.scrollBarWidth; | |
| 281 | + //width += this.scrollBarWidth; | |
| 280 | 282 | style.width = `${width}px`; |
| 283 | + style.right = `${this.showVerticalScrollBar?this.scrollBarWidth:0}px`; | |
| 281 | 284 | return style; |
| 282 | 285 | }, |
| 283 | 286 | bodyStyle () { |
| ... | ... | @@ -292,11 +295,11 @@ |
| 292 | 295 | fixedBodyStyle () { |
| 293 | 296 | let style = {}; |
| 294 | 297 | if (this.bodyHeight !== 0) { |
| 295 | - let height = this.bodyHeight + this.scrollBarWidth - 1; | |
| 298 | + let height = this.bodyHeight + (!this.showHorizontalScrollBar?this.scrollBarWidth:0) - 1; | |
| 296 | 299 | |
| 297 | 300 | // #2102 ้๏ผๅฆๆ Table ๆฒกๆ่ฎพ็ฝฎ width๏ผ่ๆฏ้ๆ็ถ็บง็ width๏ผๅบๅฎๅไนๅบ่ฏฅไธๅ ๅซๆปๅจๆก้ซๅบฆ๏ผๆไปฅ่ฟ้็ดๆฅ่ฎก็ฎ่กจๆ ผๅฎฝๅบฆ |
| 298 | 301 | const tableWidth = parseInt(getStyle(this.$el, 'width')) - 1; |
| 299 | - if ((this.width && this.width < this.tableWidth) || tableWidth < this.tableWidth){ | |
| 302 | + if ((this.width && this.width < this.tableWidth) || tableWidth < this.tableWidth+(this.showVerticalScrollBar?this.scrollBarWidth:0)){ | |
| 300 | 303 | height = this.bodyHeight; |
| 301 | 304 | } |
| 302 | 305 | // style.height = this.scrollBarWidth > 0 ? `${this.bodyHeight}px` : `${this.bodyHeight - 1}px`; |
| ... | ... | @@ -348,7 +351,13 @@ |
| 348 | 351 | this.tableWidth = parseInt(getStyle(this.$el, 'width')) - 1; |
| 349 | 352 | } |
| 350 | 353 | this.columnsWidth = {}; |
| 351 | - if (!this.$refs.tbody) return; | |
| 354 | + this.$nextTick(()=>{ | |
| 355 | + this.headerWidth = this.$refs.header.childNodes[0].offsetWidth; | |
| 356 | + if (!this.$refs.tbody) { | |
| 357 | + this.showVerticalScrollBar = false; | |
| 358 | + return; | |
| 359 | + } | |
| 360 | + }); | |
| 352 | 361 | this.$nextTick(() => { |
| 353 | 362 | let columnsWidth = {}; |
| 354 | 363 | let autoWidthIndex = -1; |
| ... | ... | @@ -358,7 +367,6 @@ |
| 358 | 367 | const $tr = this.$refs.tbody.$el.querySelectorAll('tbody tr'); |
| 359 | 368 | if ($tr.length === 0) return; |
| 360 | 369 | const $td = $tr[0].children; |
| 361 | - | |
| 362 | 370 | for (let i = 0; i < $td.length; i++) { // can not use forEach in Firefox |
| 363 | 371 | const column = this.cloneColumns[i]; |
| 364 | 372 | |
| ... | ... | @@ -375,23 +383,36 @@ |
| 375 | 383 | }; |
| 376 | 384 | } |
| 377 | 385 | this.columnsWidth = columnsWidth; |
| 378 | - this.fixedHeader(); | |
| 379 | - | |
| 380 | - if (this.$refs.tbody) { | |
| 381 | - let bodyContentEl = this.$refs.tbody.$el; | |
| 382 | - let bodyEl = bodyContentEl.parentElement; | |
| 383 | - bodyEl.className = ''; | |
| 384 | - this.$nextTick(() => { bodyEl.className = this.prefixCls + '-body'; }); | |
| 385 | - let bodyContentHeight = bodyContentEl.offsetHeight; | |
| 386 | - let bodyContentWidth = bodyContentEl.offsetWidth; | |
| 387 | - let bodyWidth = bodyEl.offsetWidth; | |
| 388 | - let bodyHeight = bodyEl.offsetHeight; | |
| 389 | - let scrollBarWidth = 0; | |
| 390 | - if (bodyWidth < bodyContentWidth) { | |
| 391 | - scrollBarWidth = this.scrollBarWidth; | |
| 386 | + this.$nextTick(()=>{ | |
| 387 | + this.fixedHeader(); | |
| 388 | + if (this.$refs.tbody) { | |
| 389 | + let bodyContentEl = this.$refs.tbody.$el; | |
| 390 | + let bodyEl = bodyContentEl.parentElement; | |
| 391 | + let bodyContentHeight = bodyContentEl.offsetHeight; | |
| 392 | + let bodyContentWidth = bodyContentEl.offsetWidth; | |
| 393 | + let bodyWidth = bodyEl.offsetWidth; | |
| 394 | + let bodyHeight = bodyEl.offsetHeight; | |
| 395 | + let scrollBarWidth = 0; | |
| 396 | + if (bodyWidth < bodyContentWidth + (bodyHeight<bodyContentHeight?this.scrollBarWidth : 0)) { | |
| 397 | + scrollBarWidth = this.scrollBarWidth; | |
| 398 | + } | |
| 399 | + | |
| 400 | + this.showVerticalScrollBar = this.bodyHeight? bodyHeight - scrollBarWidth < bodyContentHeight : false; | |
| 401 | + this.showHorizontalScrollBar = bodyWidth < bodyContentWidth + (this.showVerticalScrollBar?this.scrollBarWidth:0); | |
| 402 | + | |
| 403 | + if(this.showVerticalScrollBar){ | |
| 404 | + bodyEl.classList.add(this.prefixCls +'-overflowY'); | |
| 405 | + }else{ | |
| 406 | + bodyEl.classList.remove(this.prefixCls +'-overflowY'); | |
| 407 | + } | |
| 408 | + if(this.showHorizontalScrollBar){ | |
| 409 | + bodyEl.classList.add(this.prefixCls +'-overflowX'); | |
| 410 | + }else{ | |
| 411 | + bodyEl.classList.remove(this.prefixCls +'-overflowX'); | |
| 412 | + } | |
| 413 | + | |
| 392 | 414 | } |
| 393 | - this.showVerticalScrollBar = this.bodyHeight? bodyHeight - scrollBarWidth < bodyContentHeight : false; | |
| 394 | - } | |
| 415 | + }); | |
| 395 | 416 | } |
| 396 | 417 | }); |
| 397 | 418 | // get table real height,for fixed when set height prop,but height < table's height,show scrollBarWidth | ... | ... |
src/styles/components/table.less
| ... | ... | @@ -71,7 +71,19 @@ |
| 71 | 71 | overflow: hidden; |
| 72 | 72 | } |
| 73 | 73 | &-body{ |
| 74 | - overflow: auto; | |
| 74 | + //overflow: auto; | |
| 75 | + //position: relative; | |
| 76 | + | |
| 77 | + } | |
| 78 | + &-overflowX{ | |
| 79 | + overflow-x: scroll; | |
| 80 | + } | |
| 81 | + &-overflowY{ | |
| 82 | + overflow-y: scroll; | |
| 83 | + } | |
| 84 | + &-tip{ | |
| 85 | + overflow-x: auto; | |
| 86 | + overflow-y: hidden; | |
| 75 | 87 | //position: relative; |
| 76 | 88 | } |
| 77 | 89 | |
| ... | ... | @@ -273,7 +285,7 @@ |
| 273 | 285 | box-shadow: -2px 0 6px -2px rgba(0, 0, 0, 0.2); |
| 274 | 286 | } |
| 275 | 287 | &-fixed-header{ |
| 276 | - overflow: hidden; | |
| 288 | + overflow: visible; | |
| 277 | 289 | &-with-empty{ |
| 278 | 290 | .@{table-prefix-cls}-hidden{ |
| 279 | 291 | .@{table-prefix-cls}-sort{ | ... | ... |