@@ -65,7 +80,7 @@
key: 'data5'
},
{
- title: 'Data6',
+ title: '一二三四一二三四一二三四一二三四',
key: 'data6'
},
]
@@ -118,7 +133,7 @@
data3: Math.floor(Math.random () * 100000000),
data4: Math.floor(Math.random () * Math.random () * 10000),
data5: Math.floor(Math.random () * Math.random () * 1000000),
- data6: Math.floor(Math.random () * Math.random () * 100000000),
+ data6: ''+Math.floor(Math.random () * Math.random () * 100000000)+Math.floor(Math.random () * 100000000)+Math.floor(Math.random () * 100000000),
});
}
this.tableData1 = data;
diff --git a/src/components/table/mixin.js b/src/components/table/mixin.js
index 7a06e247..7fd69a56 100644
--- a/src/components/table/mixin.js
+++ b/src/components/table/mixin.js
@@ -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;
diff --git a/src/components/table/table-head.vue b/src/components/table/table-head.vue
index 5bca78ec..d2b4b7dd 100644
--- a/src/components/table/table-head.vue
+++ b/src/components/table/table-head.vue
@@ -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;
},
diff --git a/src/components/table/table.vue b/src/components/table/table.vue
index 4ee1f918..f5279ed9 100644
--- a/src/components/table/table.vue
+++ b/src/components/table/table.vue
@@ -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(() => {