Commit 630141897540fe21230c0003a8b11573defd0b68
1 parent
a0f48947
fix table fixed-right header
Showing
4 changed files
with
42 additions
and
4 deletions
Show diff stats
examples/routers/table.vue
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | <br><br><br><br><br> | 5 | <br><br><br><br><br> |
| 6 | <!--<Table width="550" height="200" border :columns="columns2" :data="data4"></Table>--> | 6 | <!--<Table width="550" height="200" border :columns="columns2" :data="data4"></Table>--> |
| 7 | <!--<br><br><br><br><br>--> | 7 | <!--<br><br><br><br><br>--> |
| 8 | - <Table border :columns="columns5" :data="data5"></Table> | 8 | + <Table border :columns="columns5" height="200" :data="data5"></Table> |
| 9 | <br><br><br><br><br> | 9 | <br><br><br><br><br> |
| 10 | <Table border :columns="columns6" :data="data5"></Table> | 10 | <Table border :columns="columns6" :data="data5"></Table> |
| 11 | <br><br><br><br><br> | 11 | <br><br><br><br><br> |
| @@ -109,6 +109,13 @@ | @@ -109,6 +109,13 @@ | ||
| 109 | align: 'center', | 109 | align: 'center', |
| 110 | width: 200, | 110 | width: 200, |
| 111 | fixed: 'right' | 111 | fixed: 'right' |
| 112 | + }, | ||
| 113 | + { | ||
| 114 | + title: 'Gender', | ||
| 115 | + key: 'gender', | ||
| 116 | + align: 'center', | ||
| 117 | + width: 200, | ||
| 118 | + fixed: 'right' | ||
| 112 | } | 119 | } |
| 113 | ], | 120 | ], |
| 114 | columns2: [ | 121 | columns2: [ |
src/components/table/mixin.js
| @@ -32,8 +32,17 @@ export default { | @@ -32,8 +32,17 @@ export default { | ||
| 32 | } | 32 | } |
| 33 | // when fixed type,reset first right fixed column's width | 33 | // when fixed type,reset first right fixed column's width |
| 34 | if (this.fixed === 'right' && top ) { | 34 | if (this.fixed === 'right' && top ) { |
| 35 | - //const firstFixedIndex = this.columns.findIndex((col) => col.fixed === 'right'); | ||
| 36 | - if (this.columns.length === index + 1) { | 35 | + //const firstFixedIndex = this.columns.lastIndexOf((col) => col.fixed === 'right'); |
| 36 | + let lastFixedIndex = -1; | ||
| 37 | + for(let i=0;i<this.columns.length;i++){ | ||
| 38 | + if(this.columns[i].fixed==='right'){ | ||
| 39 | + lastFixedIndex = i; | ||
| 40 | + } | ||
| 41 | + else{ | ||
| 42 | + break; | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + if (lastFixedIndex === index) { | ||
| 37 | let scrollBarWidth = this.$parent.scrollBarWidth; | 46 | let scrollBarWidth = this.$parent.scrollBarWidth; |
| 38 | if (!this.$parent.showVerticalScrollBar) scrollBarWidth = 0; | 47 | if (!this.$parent.showVerticalScrollBar) scrollBarWidth = 0; |
| 39 | width += scrollBarWidth; | 48 | width += scrollBarWidth; |
src/components/table/table.vue
| @@ -85,6 +85,7 @@ | @@ -85,6 +85,7 @@ | ||
| 85 | :obj-data="objData"></table-body> | 85 | :obj-data="objData"></table-body> |
| 86 | </div> | 86 | </div> |
| 87 | </div> | 87 | </div> |
| 88 | + <div :class="[prefixCls + '-fixed-right-header']" :style="fixedRightHeaderStyle" v-if="isRightFixed"></div> | ||
| 88 | <div :class="[prefixCls + '-footer']" v-if="showSlotFooter" ref="footer"><slot name="footer"></slot></div> | 89 | <div :class="[prefixCls + '-footer']" v-if="showSlotFooter" ref="footer"><slot name="footer"></slot></div> |
| 89 | </div> | 90 | </div> |
| 90 | <Spin fix size="large" v-if="loading"> | 91 | <Spin fix size="large" v-if="loading"> |
| @@ -199,7 +200,8 @@ | @@ -199,7 +200,8 @@ | ||
| 199 | cloneData: deepCopy(this.data), // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data | 200 | cloneData: deepCopy(this.data), // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data |
| 200 | showVerticalScrollBar:false, | 201 | showVerticalScrollBar:false, |
| 201 | showHorizontalScrollBar:false, | 202 | showHorizontalScrollBar:false, |
| 202 | - headerWidth:0 | 203 | + headerWidth:0, |
| 204 | + headerHeight:0, | ||
| 203 | }; | 205 | }; |
| 204 | }, | 206 | }, |
| 205 | computed: { | 207 | computed: { |
| @@ -293,6 +295,17 @@ | @@ -293,6 +295,17 @@ | ||
| 293 | style.right = `${this.showVerticalScrollBar?this.scrollBarWidth:0}px`; | 295 | style.right = `${this.showVerticalScrollBar?this.scrollBarWidth:0}px`; |
| 294 | return style; | 296 | return style; |
| 295 | }, | 297 | }, |
| 298 | + fixedRightHeaderStyle () { | ||
| 299 | + let style = {}; | ||
| 300 | + let width = 0; | ||
| 301 | + let height = this.headerHeight+1; | ||
| 302 | + if(this.showVerticalScrollBar){ | ||
| 303 | + width = this.scrollBarWidth; | ||
| 304 | + } | ||
| 305 | + style.width = `${width}px`; | ||
| 306 | + style.height = `${height}px`; | ||
| 307 | + return style; | ||
| 308 | + }, | ||
| 296 | bodyStyle () { | 309 | bodyStyle () { |
| 297 | let style = {}; | 310 | let style = {}; |
| 298 | if (this.bodyHeight !== 0) { | 311 | if (this.bodyHeight !== 0) { |
| @@ -345,6 +358,7 @@ | @@ -345,6 +358,7 @@ | ||
| 345 | this.columnsWidth = {}; | 358 | this.columnsWidth = {}; |
| 346 | this.$nextTick(()=>{ | 359 | this.$nextTick(()=>{ |
| 347 | this.headerWidth = this.$refs.header.childNodes[0].offsetWidth; | 360 | this.headerWidth = this.$refs.header.childNodes[0].offsetWidth; |
| 361 | + this.headerHeight = this.$refs.header.childNodes[0].offsetHeight; | ||
| 348 | if (!this.$refs.tbody) { | 362 | if (!this.$refs.tbody) { |
| 349 | this.showVerticalScrollBar = false; | 363 | this.showVerticalScrollBar = false; |
| 350 | return; | 364 | return; |
src/styles/components/table.less
| @@ -288,6 +288,14 @@ | @@ -288,6 +288,14 @@ | ||
| 288 | right: 0; | 288 | right: 0; |
| 289 | box-shadow: -2px 0 6px -2px rgba(0, 0, 0, 0.2); | 289 | box-shadow: -2px 0 6px -2px rgba(0, 0, 0, 0.2); |
| 290 | } | 290 | } |
| 291 | + &-fixed-right-header{ | ||
| 292 | + position: absolute; | ||
| 293 | + top: -1px; | ||
| 294 | + right: 0; | ||
| 295 | + background-color: @table-thead-bg; | ||
| 296 | + border-top: 1px solid @border-color-base; | ||
| 297 | + border-bottom: 1px solid @border-color-split; | ||
| 298 | + } | ||
| 291 | &-fixed-header{ | 299 | &-fixed-header{ |
| 292 | overflow: hidden; | 300 | overflow: hidden; |
| 293 | &-with-empty{ | 301 | &-with-empty{ |