iview/src/components/table/mixin.js
呼啸随风 e7f2801b5e
fix last column resize bug when no data
If a table has heigth and last column is auto width

let width = ''
// is_last_column, true && top_always_true && height_set_by_user, true
if ( this.columns.length === index + 1 && top && this.$parent.bodyHeight !== 0) {
// width will be 0 + this.$parent.scrollBarWidth === this.$parent.scrollBarWidth
// so last column will be 10~20px(the width of scrollBar)
}
there is an example with iview@2.8.0
[gist](https://gist.github.com/anonymous/e04e86c9e99d4d1e97bf327769acd345)
[demo on jsbin](http://jsbin.com/soqogagiqu)
2018-01-09 10:22:17 +08:00

40 lines
1.9 KiB
JavaScript

export default {
methods: {
alignCls (column, row = {}) {
let cellClassName = '';
if (row.cellClassName && column.key && row.cellClassName[column.key]) {
cellClassName = row.cellClassName[column.key];
}
return [
{
[`${cellClassName}`]: cellClassName, // cell className
[`${column.className}`]: column.className, // column className
[`${this.prefixCls}-column-${column.align}`]: column.align,
[`${this.prefixCls}-hidden`]: (this.fixed === 'left' && column.fixed !== 'left') || (this.fixed === 'right' && column.fixed !== 'right') || (!this.fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right'))
}
];
},
isPopperShow (column) {
return column.filters && ((!this.fixed && !column.fixed) || (this.fixed === 'left' && column.fixed === 'left') || (this.fixed === 'right' && column.fixed === 'right'));
},
setCellWidth (column, index, top) {
let width = '';
if (column.width) {
width = column.width;
} else if (this.columnsWidth[column._index]) {
width = this.columnsWidth[column._index].width;
}
// 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;
}
// 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 (width === '0') width = '';
return width;
}
}
};