Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(collections/table): line up digits in date and number columns
Elian Dorand3c05b0b49b6
diff --git a/apps/client/src/widgets/collections/table/columns.css b/apps/client/src/widgets/collections/table/columns.cssindex 2b377c26f8..82d49dafa7 100644--- a/apps/client/src/widgets/collections/table/columns.css+++ b/apps/client/src/widgets/collections/table/columns.css@@ -63,3 +63,7 @@inset-block-start: auto;inset-block-end: 0;}++.tabulator-cell.table-numeric-cell {+ font-variant-numeric: tabular-nums;+}diff --git a/apps/client/src/widgets/collections/table/columns.spec.ts b/apps/client/src/widgets/collections/table/columns.spec.tsindex 5220ed494d..ff9d8a7666 100644--- a/apps/client/src/widgets/collections/table/columns.spec.ts+++ b/apps/client/src/widgets/collections/table/columns.spec.ts@@ -184,6 +184,27 @@ describe("buildColumnDefinitions — typed columns", () => {expect(editorOf("time")).toBe("time");});+ it("sets numbers and dates in equal-width digits, so that a column of them lines up", () => {+ const columns = buildColumnDefinitions({+ info: [+ { name: "date", type: "date" },+ { name: "datetime", type: "datetime" },+ { name: "time", type: "time" },+ { name: "number", type: "number" },+ { name: "text", type: "text" }+ ],+ movableRows: false,+ existingColumnData: undefined,+ rowNumberHint: 1+ });+ const classOf = (name: string) => columns.find((column) => column.field === `labels.${name}`)?.cssClass;++ for (const name of [ "date", "datetime", "time", "number" ]) {+ expect(classOf(name)).toBe("table-numeric-cell");+ }+ expect(classOf("text")).toBeUndefined();+ });+it("hands a url column's href through the scheme guard rather than linking the value as stored", () => {const column = buildColumnDefinitions({info: [ { name: "site", type: "url" } ],@@ -239,7 +260,7 @@ describe("buildColumnDefinitions — note dates", () => {for (const field of [ "dateCreated", "dateModified" ]) {const column = columns.find((candidate) => candidate.field === field);if (!column) throw new Error(`expected a ${field} column`);- expect(column).toMatchObject({ visible: false, sorter: "string" });+ expect(column).toMatchObject({ visible: false, sorter: "string", cssClass: "table-numeric-cell" });expect(column.editor).toBeUndefined();const formatter = column.formatter;diff --git a/apps/client/src/widgets/collections/table/columns.tsx b/apps/client/src/widgets/collections/table/columns.tsxindex 6245edb0b1..b33af3b5ed 100644--- a/apps/client/src/widgets/collections/table/columns.tsx+++ b/apps/client/src/widgets/collections/table/columns.tsx@@ -21,6 +21,9 @@ import type { TableData } from "./rows.js";type ColumnType = LabelType | "relation";+/** Sets a column's digits at equal widths, so that its numbers and dates line up row to row. */+const NUMERIC_CELL_CLASS = "table-numeric-cell";+export interface AttributeDefinitionInformation {name: string;title?: string;@@ -59,21 +62,25 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {},date: {editor: "date",+ cssClass: NUMERIC_CELL_CLASS,// Values are stored as ISO ("YYYY-MM-DD"), which Tabulator would otherwise render as-is.formatter: (cell) => formatLabelDate(cell.getValue(), false)},datetime: {editor: "datetime",+ cssClass: NUMERIC_CELL_CLASS,formatter: (cell) => formatLabelDate(cell.getValue(), true)},number: {editor: "number",+ cssClass: NUMERIC_CELL_CLASS,sorter: "number"},time: {// No `format` param, so the editor stays on the stored "HH:mm" and needs no luxon — the same// value, through the same native field, as the promoted attribute of this type.- editor: "time"+ editor: "time",+ cssClass: NUMERIC_CELL_CLASS},url: {formatter: "link",@@ -128,6 +135,7 @@ function relationTitle(row: RowComponent, column: ColumnComponent): string {const noteDateColumn: Partial<ColumnDefinition> = {formatter: (cell) => formatLabelDate(cell.getValue(), true),sorter: "string",+ cssClass: NUMERIC_CELL_CLASS,visible: false};