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

54 lines
1.6 KiB
TypeScript
Raw Normal View History

import type { CellComponent, ColumnComponent, MenuObject, Tabulator } from "tabulator-tables";
2025-07-01 12:09:13 +03:00
export function applyHeaderMenu(columns: ColumnComponent[]) {
2025-07-01 12:09:13 +03:00
for (let column of columns) {
if (column.headerSort !== false) {
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;
};