Skip to content

Commit

Permalink
Table: fix sync height
Browse files Browse the repository at this point in the history
  • Loading branch information
cs1707 committed Nov 17, 2021
1 parent 363282b commit 1a3fdb2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
6 changes: 6 additions & 0 deletions packages/table/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Watcher.prototype.mutations = {
}

this.updateTableScrollY();
this.syncFixedTableRowHeight();
},

filterChange(states, options) {
Expand All @@ -111,6 +112,7 @@ Watcher.prototype.mutations = {
}

this.updateTableScrollY();
this.syncFixedTableRowHeight();
},

toggleAllSelection() {
Expand Down Expand Up @@ -144,4 +146,8 @@ Watcher.prototype.updateTableScrollY = function() {
Vue.nextTick(this.table.updateScrollY);
};

Watcher.prototype.syncFixedTableRowHeight = function() {
Vue.nextTick(() => this.table.layout.syncFixedTableRowHeight());
};

export default Watcher;
21 changes: 9 additions & 12 deletions packages/table/src/table-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export default {
border="0">
<colgroup>
{
this.columns.map(column => <col name={column.id} key={column.id} />)
this.columns
.filter((column, index) => !(this.columnsHidden[index] && this.fixed))
.map(column => <col name={column.id} key={column.id} />)
}
</colgroup>
<tbody>
Expand Down Expand Up @@ -70,15 +72,7 @@ export default {

...mapStates({
data: 'data',
columns(states) {
if (this.fixed === true || this.fixed === 'left') {
return states.fixedColumns;
}
if (this.fixed === 'right') {
return states.rightFixedColumns;
}
return states.columns;
},
columns: 'columns',
treeIndent: 'indent',
leftFixedLeafCount: 'fixedLeafColumnsLength',
rightFixedLeafCount: 'rightFixedLeafColumnsLength',
Expand Down Expand Up @@ -140,8 +134,10 @@ export default {
},

isColumnHidden(index) {
if (this.fixed === true || this.fixed === 'left' || this.fixed === 'right') {
return false;
if (this.fixed === true || this.fixed === 'left') {
return index >= this.leftFixedLeafCount;
} else if (this.fixed === 'right') {
return index < this.columnsCount - this.rightFixedLeafCount;
} else {
return (index < this.leftFixedLeafCount) || (index >= this.columnsCount - this.rightFixedLeafCount);
}
Expand Down Expand Up @@ -388,6 +384,7 @@ export default {
handleCellMouseLeave={this.handleCellMouseLeave}
isSelected={isSelected}
isExpanded={isExpanded}
fixed={this.fixed}
>
</TableRow>
);
Expand Down
4 changes: 3 additions & 1 deletion packages/table/src/table-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ class TableLayout {

const noData = !(this.store.states.data && this.store.states.data.length);
this.viewportHeight = this.scrollX ? tableHeight - (noData ? 0 : this.gutterWidth) : tableHeight;
this.syncFixedTableRowHeight();
setTimeout(() => {
this.syncFixedTableRowHeight();
});
this.updateScrollY();
this.notifyObservers('scrollable');
}
Expand Down
6 changes: 5 additions & 1 deletion packages/table/src/table-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default {
'getCellStyle',
'getCellClass',
'handleCellMouseLeave',
'handleCellMouseEnter'
'handleCellMouseEnter',
'fixed'
],
render() {
const {
Expand All @@ -38,6 +39,9 @@ export default {
<tr>
{
columns.map((column, cellIndex) => {
if (columnsHidden[cellIndex] && this.fixed) {
return null;
}
const { rowspan, colspan } = this.getSpan(row, column, $index, cellIndex);
if (!rowspan || !colspan) {
return null;
Expand Down

0 comments on commit 1a3fdb2

Please sign in to comment.