feat(hide-columns): hide empty columns per default
This commit is contained in:
parent
3fbb4db962
commit
d1232ce72d
@ -5,6 +5,8 @@ import './hide-columns.scss';
|
|||||||
const HIDE_COLUMNS_CONTAINER_IDENT = 'uw-hide-columns';
|
const HIDE_COLUMNS_CONTAINER_IDENT = 'uw-hide-columns';
|
||||||
const TABLE_HEADER_IDENT = 'uw-hide-column-header';
|
const TABLE_HEADER_IDENT = 'uw-hide-column-header';
|
||||||
|
|
||||||
|
const ASYNC_TABLE_IDENT = 'uw-async-table';
|
||||||
|
|
||||||
const TABLE_UTILS_ATTR = 'table-utils';
|
const TABLE_UTILS_ATTR = 'table-utils';
|
||||||
const TABLE_UTILS_CONTAINER_SELECTOR = `[${TABLE_UTILS_ATTR}]`;
|
const TABLE_UTILS_CONTAINER_SELECTOR = `[${TABLE_UTILS_ATTR}]`;
|
||||||
|
|
||||||
@ -158,6 +160,8 @@ export class HideColumns {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateColumnDisplay(columnIndex, hidden) {
|
updateColumnDisplay(columnIndex, hidden) {
|
||||||
|
let isColumnWithContent = false;
|
||||||
|
|
||||||
this._element.getElementsByTagName('tr').forEach(row => {
|
this._element.getElementsByTagName('tr').forEach(row => {
|
||||||
const cell = row.cells[columnIndex];
|
const cell = row.cells[columnIndex];
|
||||||
if (cell) {
|
if (cell) {
|
||||||
@ -165,9 +169,26 @@ export class HideColumns {
|
|||||||
cell.classList.add(CELL_HIDDEN_CLASS);
|
cell.classList.add(CELL_HIDDEN_CLASS);
|
||||||
} else {
|
} else {
|
||||||
cell.classList.remove(CELL_HIDDEN_CLASS);
|
cell.classList.remove(CELL_HIDDEN_CLASS);
|
||||||
|
|
||||||
|
// determine if this cell has content
|
||||||
|
if (cell.nodeName === 'TD') {
|
||||||
|
let cellHasContent = false;
|
||||||
|
if (this._elementWrapper.hasAttribute(ASYNC_TABLE_IDENT)) {
|
||||||
|
cell.children.forEach(child => {
|
||||||
|
cellHasContent = cellHasContent || !isEmptyElement(child);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cellHasContent = !isEmptyElement(cell);
|
||||||
|
}
|
||||||
|
isColumnWithContent = isColumnWithContent || cellHasContent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!hidden && !isColumnWithContent) {
|
||||||
|
this.updateColumnDisplay(columnIndex, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHider(hider, hidden) {
|
updateHider(hider, hidden) {
|
||||||
@ -216,3 +237,12 @@ export class HideColumns {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isEmptyElement(element) {
|
||||||
|
for (let child of element.childNodes) {
|
||||||
|
if (child.nodeName !== '#comment')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user