Commit 630141897540fe21230c0003a8b11573defd0b68

Authored by huanghong
1 parent a0f48947

fix table fixed-right header

examples/routers/table.vue
... ... @@ -5,7 +5,7 @@
5 5 <br><br><br><br><br>
6 6 <!--<Table width="550" height="200" border :columns="columns2" :data="data4"></Table>-->
7 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 9 <br><br><br><br><br>
10 10 <Table border :columns="columns6" :data="data5"></Table>
11 11 <br><br><br><br><br>
... ... @@ -109,6 +109,13 @@
109 109 align: 'center',
110 110 width: 200,
111 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 121 columns2: [
... ...
src/components/table/mixin.js
... ... @@ -32,8 +32,17 @@ export default {
32 32 }
33 33 // when fixed type,reset first right fixed column's width
34 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 46 let scrollBarWidth = this.$parent.scrollBarWidth;
38 47 if (!this.$parent.showVerticalScrollBar) scrollBarWidth = 0;
39 48 width += scrollBarWidth;
... ...
src/components/table/table.vue
... ... @@ -85,6 +85,7 @@
85 85 :obj-data="objData"></table-body>
86 86 </div>
87 87 </div>
  88 + <div :class="[prefixCls + '-fixed-right-header']" :style="fixedRightHeaderStyle" v-if="isRightFixed"></div>
88 89 <div :class="[prefixCls + '-footer']" v-if="showSlotFooter" ref="footer"><slot name="footer"></slot></div>
89 90 </div>
90 91 <Spin fix size="large" v-if="loading">
... ... @@ -199,7 +200,8 @@
199 200 cloneData: deepCopy(this.data), // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data
200 201 showVerticalScrollBar:false,
201 202 showHorizontalScrollBar:false,
202   - headerWidth:0
  203 + headerWidth:0,
  204 + headerHeight:0,
203 205 };
204 206 },
205 207 computed: {
... ... @@ -293,6 +295,17 @@
293 295 style.right = `${this.showVerticalScrollBar?this.scrollBarWidth:0}px`;
294 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 309 bodyStyle () {
297 310 let style = {};
298 311 if (this.bodyHeight !== 0) {
... ... @@ -345,6 +358,7 @@
345 358 this.columnsWidth = {};
346 359 this.$nextTick(()=>{
347 360 this.headerWidth = this.$refs.header.childNodes[0].offsetWidth;
  361 + this.headerHeight = this.$refs.header.childNodes[0].offsetHeight;
348 362 if (!this.$refs.tbody) {
349 363 this.showVerticalScrollBar = false;
350 364 return;
... ...
src/styles/components/table.less
... ... @@ -288,6 +288,14 @@
288 288 right: 0;
289 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 299 &-fixed-header{
292 300 overflow: hidden;
293 301 &-with-empty{
... ...