Table: Fix error in cacluating hidden in table-header and table-body

This commit is contained in:
lirilsu 2017-10-18 11:01:32 +08:00 committed by 杨奕
parent ba3315a728
commit d8dd114a16
3 changed files with 43 additions and 12 deletions

View File

@ -136,6 +136,14 @@ export default {
return this.store.states.columns.length;
},
leftFixedLeafCount() {
return this.store.states.fixedLeafColumnsLength;
},
rightFixedLeafCount() {
return this.store.states.rightFixedLeafColumnsLength;
},
leftFixedCount() {
return this.store.states.fixedColumns.length;
},
@ -170,11 +178,11 @@ export default {
isColumnHidden(index) {
if (this.fixed === true || this.fixed === 'left') {
return index >= this.leftFixedCount;
return index >= this.leftFixedLeafCount;
} else if (this.fixed === 'right') {
return index < this.columnsCount - this.rightFixedCount;
return index < this.columnsCount - this.rightFixedLeafCount;
} else {
return (index < this.leftFixedCount) || (index >= this.columnsCount - this.rightFixedCount);
return (index < this.leftFixedLeafCount) || (index >= this.columnsCount - this.rightFixedLeafCount);
}
},

View File

@ -188,6 +188,14 @@ export default {
return this.store.states.rightFixedColumns.length;
},
leftFixedLeafCount() {
return this.store.states.fixedLeafColumnsLength;
},
rightFixedLeafCount() {
return this.store.states.rightFixedLeafColumnsLength;
},
columns() {
return this.store.states.columns;
},
@ -234,16 +242,17 @@ export default {
methods: {
isCellHidden(index, columns) {
let start = 0;
for (let i = 0; i < index; i++) {
start += columns[i].colSpan;
}
const after = start + columns[index].colSpan - 1;
if (this.fixed === true || this.fixed === 'left') {
return index >= this.leftFixedCount;
return after >= this.leftFixedLeafCount;
} else if (this.fixed === 'right') {
let before = 0;
for (let i = 0; i < index; i++) {
before += columns[i].colSpan;
}
return before < this.columnsCount - this.rightFixedCount;
return start < this.columnsCount - this.rightFixedLeafCount;
} else {
return (index < this.leftFixedCount) || (index >= this.columnsCount - this.rightFixedCount);
return (after < this.leftFixedLeafCount) || (start >= this.columnsCount - this.rightFixedLeafCount);
}
},

View File

@ -56,6 +56,9 @@ const TableStore = function(table, initialState = {}) {
columns: [],
fixedColumns: [],
rightFixedColumns: [],
leafColumns: [],
fixedLeafColumns: [],
rightFixedLeafColumns: [],
isComplex: false,
_data: null,
filteredData: null,
@ -322,8 +325,19 @@ TableStore.prototype.updateColumns = function() {
_columns[0].fixed = true;
states.fixedColumns.unshift(_columns[0]);
}
states.originColumns = [].concat(states.fixedColumns).concat(_columns.filter((column) => !column.fixed)).concat(states.rightFixedColumns);
states.columns = doFlattenColumns(states.originColumns);
const notFixedColumns = _columns.filter(column => !column.fixed);
states.originColumns = [].concat(states.fixedColumns).concat(notFixedColumns).concat(states.rightFixedColumns);
const leafColumns = doFlattenColumns(notFixedColumns);
const fixedLeafColumns = doFlattenColumns(states.fixedColumns);
const rightFixedLeafColumns = doFlattenColumns(states.rightFixedColumns);
states.leafColumnsLength = leafColumns.length;
states.fixedLeafColumnsLength = fixedLeafColumns.length;
states.rightFixedLeafColumnsLength = rightFixedLeafColumns.length;
states.columns = [].concat(fixedLeafColumns).concat(leafColumns).concat(rightFixedLeafColumns);
states.isComplex = states.fixedColumns.length > 0 || states.rightFixedColumns.length > 0;
};