refactor(hide-columns): minor renaming and preparation for css work
This commit is contained in:
parent
bc023f5bfb
commit
68fc4e4c3a
@ -57,12 +57,12 @@ export class HideColumns {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setupHideButton(th, prevHidden) {
|
setupHideButton(th, prevHidden) {
|
||||||
const hider = document.createElement('button');
|
const hider = document.createElement('span');
|
||||||
hider.setAttribute(HIDER_TEXT_ATTR, th.innerText);
|
hider.setAttribute(HIDER_TEXT_ATTR, th.innerText);
|
||||||
|
|
||||||
hider.addEventListener('click', (event) => {
|
hider.addEventListener('click', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.toggleColumnVisibility(th, hider);
|
this.switchColumnDisplay(th, hider);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO fade in / fade out animation in css
|
// TODO fade in / fade out animation in css
|
||||||
@ -81,23 +81,18 @@ export class HideColumns {
|
|||||||
this._tableUtilContainer.appendChild(hider);
|
this._tableUtilContainer.appendChild(hider);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO better name
|
switchColumnDisplay(th, hider) {
|
||||||
toggleColumnVisibility(th, hider) {
|
|
||||||
const storageKey = this.getStorageKey(th);
|
const storageKey = this.getStorageKey(th);
|
||||||
|
|
||||||
const hidden = !this._storageManager.load(storageKey);
|
const hidden = !this._storageManager.load(storageKey);
|
||||||
|
|
||||||
// hide/unhide column
|
|
||||||
this.updateColumnDisplay(th.cellIndex, hidden);
|
this.updateColumnDisplay(th.cellIndex, hidden);
|
||||||
|
|
||||||
// tweak hider button
|
|
||||||
this.updateHider(hider, hidden);
|
this.updateHider(hider, hidden);
|
||||||
|
|
||||||
// persist new hidden setting for column
|
// persist new hidden setting for column
|
||||||
this._storageManager.save(storageKey, hidden);
|
this._storageManager.save(storageKey, hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO better name
|
|
||||||
updateColumnDisplay(columnIndex, hidden) {
|
updateColumnDisplay(columnIndex, hidden) {
|
||||||
this._element.getElementsByTagName('tr').forEach(row => {
|
this._element.getElementsByTagName('tr').forEach(row => {
|
||||||
if (row.cells[columnIndex]) {
|
if (row.cells[columnIndex]) {
|
||||||
@ -106,7 +101,6 @@ export class HideColumns {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO better name
|
|
||||||
updateHider(hider, hidden) {
|
updateHider(hider, hidden) {
|
||||||
// TODO set css classes instead
|
// TODO set css classes instead
|
||||||
if (hidden) {
|
if (hidden) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user