Files
Trilium/apps/client/src/widgets/view_widgets/table_view/renderer.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

import { createGrid, AllCommunityModule, ModuleRegistry, columnDropStyleBordered, GridOptions } from "ag-grid-community";
import { buildData, type TableData } from "./data.js";
2025-06-25 11:03:43 +03:00
import FNote from "../../../entities/fnote.js";
import getPromotedAttributeInformation, { PromotedAttributeInformation } from "./parser.js";
import { setLabel } from "../../../services/attributes.js";
2025-06-25 10:49:33 +03:00
ModuleRegistry.registerModules([ AllCommunityModule ]);
export default function renderTable(el: HTMLElement, parentNote: FNote, notes: FNote[]) {
const info = getPromotedAttributeInformation(parentNote);
2025-06-25 10:49:33 +03:00
createGrid(el, {
...buildData(info, notes),
...setupEditing(info)
2025-06-25 10:49:33 +03:00
});
}
function setupEditing(info: PromotedAttributeInformation[]): GridOptions<TableData> {
return {
onCellValueChanged(event) {
if (event.type !== "cellValueChanged") {
return;
}
const noteId = event.data.noteId;
const name = event.colDef.field;
if (!name) {
return;
}
const { newValue } = event;
setLabel(noteId, name, newValue);
}
}
}