Files
Trilium/apps/client/src/widgets/view_widgets/table_view/header-menu.ts

53 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-07-01 12:09:13 +03:00
import type { CellComponent, MenuObject, Tabulator } from "tabulator-tables";
export function applyHeaderMenu(columns) {
//apply header menu to each column
2025-07-01 12:09:13 +03:00
for (let column of columns) {
column.headerMenu = headerMenu;
}
}
2025-07-01 12:09:13 +03:00
function headerMenu(this: Tabulator) {
const menu: MenuObject<CellComponent>[] = [];
const columns = this.getColumns();
2025-07-01 12:09:13 +03:00
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({
2025-07-01 12:09:13 +03:00
label: label,
action: function (e) {
//prevent menu closing
e.stopPropagation();
//toggle current column visibility
column.toggle();
//change menu item icon
2025-07-01 12:09:13 +03:00
if (column.isVisible()) {
icon.classList.remove("bx-empty");
icon.classList.add("bx-check");
2025-07-01 12:09:13 +03:00
} else {
icon.classList.remove("bx-check");
icon.classList.add("bx-empty");
}
}
});
}
2025-07-01 12:09:13 +03:00
return menu;
};