Skip to content

Build your personal knowledge base with Trilium Notes

chore(views/table): support more data types

Elian Dorane7ca56e061e8
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 d89a449f6e..b09cc1fecc 100644
--- a/apps/client/src/widgets/view_widgets/table_view/data.ts
+++ b/apps/client/src/widgets/view_widgets/table_view/data.ts
@@ -17,6 +17,35 @@ export interface PromotedAttributeInformation {
type?: LabelType;
}
+const labelTypeMappings: Record<LabelType, Partial<ColumnDefinition>> = {
+ text: {
+ editor: "input"
+ },
+ boolean: {
+ formatter: "tickCross",
+ editor: "tickCross"
+ },
+ date: {
+ formatter: "datetime",
+ editor: "date",
+ },
+ datetime: {
+ formatter: "datetime",
+ editor: "datetime"
+ },
+ number: {
+ editor: "number"
+ },
+ time: {
+ formatter: "datetime",
+ editor: "datetime"
+ },
+ url: {
+ formatter: "link",
+ editor: "input"
+ }
+};
+
type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object';
export async function buildData(parentNote: FNote, info: PromotedAttributeInformation[], notes: FNote[]) {
@@ -69,8 +98,8 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
columnDefs.push({
field: `labels.${name}`,
title: title ?? name,
- editor: "input"
- // cellDataType: mapDataType(type),
+ editor: "input",
+ ...labelTypeMappings[type ?? "text"],
});
}
@@ -93,24 +122,6 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
return columnDefs;
}
-function mapDataType(labelType: LabelType | undefined): GridLabelType {
- if (!labelType) {
- return "text";
- }
-
- switch (labelType) {
- case "number":
- return "number";
- case "boolean":
- return "boolean";
- case "date":
- return "dateString";
- case "text":
- default:
- return "text"
- }
-}
-
export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: PromotedAttributeInformation[]) {
const definitions: GridOptions<TableData>["rowData"] = [];
for (const branch of parentNote.getChildBranches()) {