diff --git a/packages/table/src/layout-observer.js b/packages/table/src/layout-observer.js index 6e9a1c30bc1..605a0f200d8 100644 --- a/packages/table/src/layout-observer.js +++ b/packages/table/src/layout-observer.js @@ -33,10 +33,10 @@ export default { }, methods: { - onColumnsChange() { + onColumnsChange(layout) { const cols = this.$el.querySelectorAll('colgroup > col'); if (!cols.length) return; - const flattenColumns = this.tableLayout.getFlattenColumns(); + const flattenColumns = layout.getFlattenColumns(); const columnsMap = {}; flattenColumns.forEach((column) => { columnsMap[column.id] = column; diff --git a/packages/table/src/table-layout.js b/packages/table/src/table-layout.js index f3ac5ae7f54..6365dc9b550 100644 --- a/packages/table/src/table-layout.js +++ b/packages/table/src/table-layout.js @@ -97,7 +97,7 @@ class TableLayout { if (this.showHeader && !headerWrapper) return; // fix issue (https://github.com/ElemeFE/element/pull/16956) - const headerTrElm = headerWrapper.querySelector('.el-table__header tr'); + const headerTrElm = headerWrapper ? headerWrapper.querySelector('.el-table__header tr') : null; const noneHeader = this.headerDisplayNone(headerTrElm); const headerHeight = this.headerHeight = !this.showHeader ? 0 : headerWrapper.offsetHeight; @@ -119,6 +119,7 @@ class TableLayout { } headerDisplayNone(elm) { + if (!elm) return true; let headerChild = elm; while (headerChild.tagName !== 'DIV') { if (getComputedStyle(headerChild).display === 'none') { diff --git a/packages/table/src/table.vue b/packages/table/src/table.vue index c4c69172f9a..e0061e6282e 100644 --- a/packages/table/src/table.vue +++ b/packages/table/src/table.vue @@ -383,6 +383,7 @@ updateScrollY() { const changed = this.layout.updateScrollY(); if (changed) { + this.layout.notifyObservers('scrollable'); this.layout.updateColumnsWidth(); } },