Skip to content

Build your personal knowledge base with Trilium Notes

feat(views/table): basic formatter for relations

Elian Doranb29364339891
diff --git a/apps/client/src/widgets/view_widgets/table_view/data.ts b/apps/client/src/widgets/view_widgets/table_view/data.ts
index a86886f709..4dd8c7b120 100644
--- a/apps/client/src/widgets/view_widgets/table_view/data.ts
+++ b/apps/client/src/widgets/view_widgets/table_view/data.ts
@@ -2,7 +2,7 @@ import FNote from "../../../entities/fnote.js";
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
import type { ColumnDefinition } from "tabulator-tables";
import link from "../../../services/link.js";
-import RelationEditor from "./relation_editor.js";
+import { RelationEditor, RelationFormatter } from "./relation_editor.js";
export type TableData = {
iconClass: string;
@@ -46,7 +46,8 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {
editor: "input"
},
relation: {
- editor: RelationEditor
+ editor: RelationEditor,
+ formatter: RelationFormatter
}
};
diff --git a/apps/client/src/widgets/view_widgets/table_view/relation_editor.ts b/apps/client/src/widgets/view_widgets/table_view/relation_editor.ts
index 34efad4f61..5b463afd16 100644
--- a/apps/client/src/widgets/view_widgets/table_view/relation_editor.ts
+++ b/apps/client/src/widgets/view_widgets/table_view/relation_editor.ts
@@ -1,7 +1,7 @@
import { CellComponent } from "tabulator-tables";
import note_autocomplete from "../../../services/note_autocomplete";
-export default function RelationEditor(cell: CellComponent, onRendered, success, cancel, editorParams){
+export function RelationEditor(cell: CellComponent, onRendered, success, cancel, editorParams){
//cell - the cell component for the editable cell
//onRendered - function to call when the editor has been rendered
//success - function to call to pass thesuccessfully updated value to Tabulator
@@ -38,3 +38,12 @@ export default function RelationEditor(cell: CellComponent, onRendered, success,
//return the editor element
return editor;
};
+
+export function RelationFormatter(cell: CellComponent, formatterParams, onRendered) {
+ const noteId = cell.getValue();
+ if (!noteId) {
+ return "";
+ }
+
+ return `<a href="#root/${noteId}">Title goes here</a>`;
+}