mirror of https://github.com/ElemeFE/element
[Table] Improve fixed implement method.
parent
9f77e088c5
commit
41490c55e1
|
@ -52,10 +52,10 @@ export default {
|
||||||
on-mouseenter={ _ => this.handleMouseEnter($index) }
|
on-mouseenter={ _ => this.handleMouseEnter($index) }
|
||||||
class={ this.getRowClass(row, $index) }>
|
class={ this.getRowClass(row, $index) }>
|
||||||
{
|
{
|
||||||
this._l(this.columns, (column) =>
|
this._l(this.columns, (column, cellIndex) =>
|
||||||
<td
|
<td
|
||||||
style={ this.getColumnWhiteSpaceStyle(column) }
|
style={ this.getColumnWhiteSpaceStyle(column) }
|
||||||
class={ [column.id, column.align] }
|
class={ [column.id, column.align, this.isCellHidden(cellIndex) ? 'hidden' : '' ] }
|
||||||
on-mouseenter={ ($event) => this.handleCellMouseEnter($event, row) }
|
on-mouseenter={ ($event) => this.handleCellMouseEnter($event, row) }
|
||||||
on-mouseleave={ this.handleCellMouseLeave }>
|
on-mouseleave={ this.handleCellMouseLeave }>
|
||||||
{
|
{
|
||||||
|
@ -81,18 +81,24 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return this.store.states.data;
|
return this.store.states.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
hoverRowIndex() {
|
hoverRowIndex() {
|
||||||
return this.store.states.hoverRow;
|
return this.store.states.hoverRow;
|
||||||
},
|
},
|
||||||
currentRow() {
|
|
||||||
return this.store.states.currentRow;
|
columnsCount() {
|
||||||
|
return this.store.states.columns.length;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
leftFixedCount() {
|
||||||
|
return this.store.states.fixedColumns.length;
|
||||||
|
},
|
||||||
|
|
||||||
|
rightFixedCount() {
|
||||||
|
return this.store.states.rightFixedColumns.length;
|
||||||
|
},
|
||||||
|
|
||||||
columns() {
|
columns() {
|
||||||
if (this.fixed === true || this.fixed === 'left') {
|
|
||||||
return this.store.states.fixedColumns;
|
|
||||||
} else if (this.fixed === 'right') {
|
|
||||||
return this.store.states.rightFixedColumns;
|
|
||||||
}
|
|
||||||
return this.store.states.columns;
|
return this.store.states.columns;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -104,11 +110,18 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
isCellHidden(index) {
|
||||||
|
if (this.fixed === true || this.fixed === 'left') {
|
||||||
|
return index >= this.leftFixedCount;
|
||||||
|
} else if (this.fixed === 'right') {
|
||||||
|
return index < this.columnsCount - this.rightFixedCount;
|
||||||
|
} else {
|
||||||
|
return (index < this.leftFixedCount) || (index >= this.columnsCount - this.rightFixedCount);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getRowClass(row, index) {
|
getRowClass(row, index) {
|
||||||
const classes = [];
|
const classes = [];
|
||||||
if (row === this.currentRow) {
|
|
||||||
classes.push('current-row');
|
|
||||||
}
|
|
||||||
if (this.hoverRowIndex === index) {
|
if (this.hoverRowIndex === index) {
|
||||||
classes.push('hover-row');
|
classes.push('hover-row');
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@ export default {
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
{
|
{
|
||||||
this._l(this.columns, column =>
|
this._l(this.columns, (column, cellIndex) =>
|
||||||
<th
|
<th
|
||||||
on-mousemove={ ($event) => this.handleMouseMove($event, column) }
|
on-mousemove={ ($event) => this.handleMouseMove($event, column) }
|
||||||
on-mouseout={ this.handleMouseOut }
|
on-mouseout={ this.handleMouseOut }
|
||||||
on-mousedown={ ($event) => this.handleMouseDown($event, column) }
|
on-mousedown={ ($event) => this.handleMouseDown($event, column) }
|
||||||
on-click={ ($event) => this.handleHeaderClick($event, column) }
|
on-click={ ($event) => this.handleHeaderClick($event, column) }
|
||||||
class={ [column.id, column.direction, column.align] }>
|
class={ [column.id, column.direction, column.align, this.isCellHidden(cellIndex) ? 'hidden' : ''] }>
|
||||||
{
|
{
|
||||||
[
|
[
|
||||||
column.headerTemplate
|
column.headerTemplate
|
||||||
|
@ -82,17 +82,34 @@ export default {
|
||||||
return this.store.states.isAllSelected;
|
return this.store.states.isAllSelected;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
columnsCount() {
|
||||||
|
return this.store.states.columns.length;
|
||||||
|
},
|
||||||
|
|
||||||
|
leftFixedCount() {
|
||||||
|
return this.store.states.fixedColumns.length;
|
||||||
|
},
|
||||||
|
|
||||||
|
rightFixedCount() {
|
||||||
|
return this.store.states.rightFixedColumns.length;
|
||||||
|
},
|
||||||
|
|
||||||
columns() {
|
columns() {
|
||||||
if (this.fixed === true || this.fixed === 'left') {
|
|
||||||
return this.store.states.fixedColumns;
|
|
||||||
} else if (this.fixed === 'right') {
|
|
||||||
return this.store.states.rightFixedColumns;
|
|
||||||
}
|
|
||||||
return this.store.states.columns;
|
return this.store.states.columns;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
isCellHidden(index) {
|
||||||
|
if (this.fixed === true || this.fixed === 'left') {
|
||||||
|
return index >= this.leftFixedCount;
|
||||||
|
} else if (this.fixed === 'right') {
|
||||||
|
return index < this.columnsCount - this.rightFixedCount;
|
||||||
|
} else {
|
||||||
|
return (index < this.leftFixedCount) || (index >= this.columnsCount - this.rightFixedCount);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
toggleAllSelection() {
|
toggleAllSelection() {
|
||||||
this.store.commit('toggleAllSelection');
|
this.store.commit('toggleAllSelection');
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { getScrollBarWidth } from './util';
|
import { getScrollBarWidth } from './util';
|
||||||
import Vue from 'vue';
|
|
||||||
|
|
||||||
let GUTTER_WIDTH;
|
let GUTTER_WIDTH;
|
||||||
|
|
||||||
|
@ -40,30 +39,6 @@ class TableLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syncHeight() {
|
|
||||||
Vue.nextTick(() => {
|
|
||||||
const { bodyWrapper, fixedBodyWrapper } = this.table.$refs;
|
|
||||||
|
|
||||||
// 若非固定列中的某行内容被撑高, 需要固定列中对应行高度与其保持一致
|
|
||||||
const bodyHeight = bodyWrapper.offsetHeight;
|
|
||||||
const fixedBodyHeight = fixedBodyWrapper.offsetHeight;
|
|
||||||
|
|
||||||
if (bodyHeight !== fixedBodyHeight) {
|
|
||||||
const rows = bodyWrapper.querySelectorAll('tr');
|
|
||||||
const fixedRows = fixedBodyWrapper.querySelectorAll('tr');
|
|
||||||
|
|
||||||
[].forEach.call(rows, (row, i) => {
|
|
||||||
const fixedRow = fixedRows[i];
|
|
||||||
const rowHeight = row.offsetHeight;
|
|
||||||
const fixedRowHeight = fixedRow.offsetHeight;
|
|
||||||
if (rowHeight !== fixedRowHeight) {
|
|
||||||
fixedRow.style.height = rowHeight + 'px';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateScrollY() {
|
updateScrollY() {
|
||||||
const bodyWrapper = this.table.$refs.bodyWrapper;
|
const bodyWrapper = this.table.$refs.bodyWrapper;
|
||||||
if (this.table.$el && bodyWrapper) {
|
if (this.table.$el && bodyWrapper) {
|
||||||
|
|
|
@ -34,7 +34,6 @@ const TableStore = function(table, initialState = {}) {
|
||||||
selection: [],
|
selection: [],
|
||||||
reserveSelection: false,
|
reserveSelection: false,
|
||||||
selectable: null,
|
selectable: null,
|
||||||
currentRow: null,
|
|
||||||
hoverRow: null
|
hoverRow: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,14 +76,12 @@ TableStore.prototype.mutations = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (states.fixedColumns.length > 0 || states.rightFixedColumns.length > 0) Vue.nextTick(() => this.table.syncHeight());
|
|
||||||
Vue.nextTick(() => this.table.updateScrollY());
|
Vue.nextTick(() => this.table.updateScrollY());
|
||||||
},
|
},
|
||||||
|
|
||||||
changeSortCondition(states) {
|
changeSortCondition(states) {
|
||||||
states.data = orderBy((states._data || []), states.sortCondition.property, states.sortCondition.direction);
|
states.data = orderBy((states._data || []), states.sortCondition.property, states.sortCondition.direction);
|
||||||
|
|
||||||
if (states.fixedColumns.length > 0 || states.rightFixedColumns.length > 0) Vue.nextTick(() => this.table.syncHeight());
|
|
||||||
Vue.nextTick(() => this.table.updateScrollY());
|
Vue.nextTick(() => this.table.updateScrollY());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -162,10 +162,6 @@
|
||||||
this.layout.updateScrollY();
|
this.layout.updateScrollY();
|
||||||
},
|
},
|
||||||
|
|
||||||
syncHeight() {
|
|
||||||
this.layout.syncHeight();
|
|
||||||
},
|
|
||||||
|
|
||||||
bindEvents() {
|
bindEvents() {
|
||||||
const { bodyWrapper, headerWrapper } = this.$refs;
|
const { bodyWrapper, headerWrapper } = this.$refs;
|
||||||
const refs = this.$refs;
|
const refs = this.$refs;
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
& th, td {
|
& th, td {
|
||||||
height: 20px;
|
height: 40px;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
@ -110,6 +110,7 @@
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
box-shadow: 1px 0 8px #d3d4d6;
|
box-shadow: 1px 0 8px #d3d4d6;
|
||||||
|
overflow-x: hidden;
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
content: '';
|
content: '';
|
||||||
|
@ -129,6 +130,11 @@
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|
||||||
box-shadow: -1px 0 8px #d3d4d6;
|
box-shadow: -1px 0 8px #d3d4d6;
|
||||||
|
|
||||||
|
.el-table__fixed-header-wrapper, .el-table__fixed-body-wrapper {
|
||||||
|
left: auto;
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@e fixed-header-wrapper {
|
@e fixed-header-wrapper {
|
||||||
|
@ -251,11 +257,18 @@
|
||||||
width: 0;
|
width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
& td .cell {
|
& td.hidden, th.hidden {
|
||||||
|
> * {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .cell {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
line-height: 40px;
|
white-space: normal;
|
||||||
|
line-height: 24px;
|
||||||
padding-left: 18px;
|
padding-left: 18px;
|
||||||
padding-right: 18px;
|
padding-right: 18px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue