From c5197928b12861599338a87dda9562ff16782332 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 7 Feb 2020 21:33:32 +0100 Subject: [PATCH] feat(hide-columns): don't break on dom changes --- frontend/src/utils/hide-columns/hide-columns.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/frontend/src/utils/hide-columns/hide-columns.js b/frontend/src/utils/hide-columns/hide-columns.js index 0c0187f23..77382e322 100644 --- a/frontend/src/utils/hide-columns/hide-columns.js +++ b/frontend/src/utils/hide-columns/hide-columns.js @@ -31,6 +31,8 @@ export class HideColumns { _autoHide; + _mutationObserver; + headerToHider = new Map(); hiderToHeader = new Map(); @@ -69,6 +71,9 @@ export class HideColumns { } [...this._element.querySelectorAll('th')].filter(th => !th.hasAttribute(HIDE_COLUMNS_NO_HIDE)).forEach(th => this.setupHideButton(th)); + + this._mutationObserver = new MutationObserver(this._tableMutated.bind(this)); + this._mutationObserver.observe(this._element, { childList: true, subtree: true }); } setupHideButton(th) { @@ -217,6 +222,15 @@ export class HideColumns { hider.style.top = thR.height + 'px'; } + _tableMutated(mutationList, observer) { + console.log('_tableMutated', mutationList, observer); + + if (!Array.from(mutationList).some(mutation => mutation.type === 'childList')) + return; + + [...this._element.querySelectorAll('th')].filter(th => !th.hasAttribute(HIDE_COLUMNS_NO_HIDE)).forEach(th => this.updateColumnDisplay(this.colIndex(th), this.isHiddenColumn(th))); + } + getStorageKey(th) { // get handler name const handlerIdent = document.querySelector('[uw-handler]').getAttribute('uw-handler');