feat(views/table): introduce hiding of columns

This commit is contained in:
Elian Doran
2025-06-29 22:26:25 +03:00
parent cedf91ea1a
commit c5cc1fcc1e
2 changed files with 58 additions and 3 deletions

View File

@@ -0,0 +1,51 @@
export function applyHeaderMenu(columns) {
//apply header menu to each column
for(let column of columns){
column.headerMenu = headerMenu;
}
}
function headerMenu(){
var menu = [];
var columns = this.getColumns();
for(let column of columns){
//create checkbox element using font awesome icons
let icon = document.createElement("i");
icon.classList.add("bx");
icon.classList.add(column.isVisible() ? "bx-check" : "bx-empty");
//build label
let label = document.createElement("span");
let title = document.createElement("span");
title.textContent = " " + column.getDefinition().title;
label.appendChild(icon);
label.appendChild(title);
//create menu item
menu.push({
label:label,
action:function(e){
//prevent menu closing
e.stopPropagation();
//toggle current column visibility
column.toggle();
//change menu item icon
if(column.isVisible()){
icon.classList.remove("bx-empty");
icon.classList.add("bx-check");
}else{
icon.classList.remove("bx-check");
icon.classList.add("bx-empty");
}
}
});
}
return menu;
};