feat(hide-columns): don't break on dom changes

This commit is contained in:
Gregor Kleen 2020-02-07 21:33:32 +01:00
parent 10de1a7de7
commit c5197928b1

View File

@ -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');