fixed table scrollbar bug

This commit is contained in:
huanghong 2018-03-16 21:17:33 +08:00
parent 6bc3b19f22
commit 47638ad84a
4 changed files with 38 additions and 7 deletions

View file

@ -26,12 +26,18 @@ export default {
}
// when browser has scrollBar,set a width to resolve scroll position bug
if (width && this.columns.length === index + 1 && top && this.$parent.bodyHeight !== 0) {
width += this.$parent.scrollBarWidth;
let scrollBarWidth = this.$parent.scrollBarWidth;
if (!this.$parent.showScrollBar()) scrollBarWidth = 0;
width += scrollBarWidth;
}
// when fixed type,reset first right fixed column's width
if (this.fixed === 'right') {
const firstFixedIndex = this.columns.findIndex((col) => col.fixed === 'right');
if (firstFixedIndex === index) width += this.$parent.scrollBarWidth;
if (firstFixedIndex === index) {
let scrollBarWidth = this.$parent.scrollBarWidth;
if (!this.$parent.showScrollBar()) scrollBarWidth = 0;
width += scrollBarWidth;
}
}
if (width === '0') width = '';
return width;

View file

@ -85,7 +85,9 @@
computed: {
styles () {
const style = Object.assign({}, this.styleObject);
const width = this.$parent.bodyHeight === 0 ? parseInt(this.styleObject.width) : parseInt(this.styleObject.width) + this.$parent.scrollBarWidth;
let scrollBarWidth = this.$parent.scrollBarWidth;
if(!this.$parent.showScrollBar()) scrollBarWidth = 0;
const width = this.$parent.bodyHeight === 0 ? parseInt(this.styleObject.width) : parseInt(this.styleObject.width) + scrollBarWidth;
style.width = `${width}px`;
return style;
},

View file

@ -338,6 +338,12 @@
rowClsName (index) {
return this.rowClassName(this.data[index], index);
},
showScrollBar () {
if (!this.$refs.tbody) return false;
let bodyContent = this.$refs.tbody.$el;
let bodyContentHeight = parseInt(getStyle(bodyContent, 'height'));
return this.bodyHeight? this.bodyHeight < bodyContentHeight : false;
},
handleResize () {
this.$nextTick(() => {
const allWidth = !this.columns.some(cell => !cell.width); // each column set a width
@ -374,6 +380,7 @@
};
}
this.columnsWidth = columnsWidth;
this.fixedHeader();
}
});
// get table real height,for fixed when set height prop,but height < table's height,show scrollBarWidth
@ -478,6 +485,7 @@
}
this.$emit('on-selection-change', selection);
},
fixedHeader () {
if (this.height) {
this.$nextTick(() => {