mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	chore(views/table): support more data types
This commit is contained in:
		| @@ -17,6 +17,35 @@ export interface PromotedAttributeInformation { | |||||||
|     type?: LabelType; |     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'; | type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object'; | ||||||
|  |  | ||||||
| export async function buildData(parentNote: FNote, info: PromotedAttributeInformation[], notes: FNote[]) { | export async function buildData(parentNote: FNote, info: PromotedAttributeInformation[], notes: FNote[]) { | ||||||
| @@ -69,8 +98,8 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) { | |||||||
|         columnDefs.push({ |         columnDefs.push({ | ||||||
|             field: `labels.${name}`, |             field: `labels.${name}`, | ||||||
|             title: title ?? name, |             title: title ?? name, | ||||||
|             editor: "input" |             editor: "input", | ||||||
|             // cellDataType: mapDataType(type), |             ...labelTypeMappings[type ?? "text"], | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -93,24 +122,6 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) { | |||||||
|     return columnDefs; |     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[]) { | export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: PromotedAttributeInformation[]) { | ||||||
|     const definitions: GridOptions<TableData>["rowData"] = []; |     const definitions: GridOptions<TableData>["rowData"] = []; | ||||||
|     for (const branch of parentNote.getChildBranches()) { |     for (const branch of parentNote.getChildBranches()) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user