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
fix(collections/table): line up headers with their column's cells
Elian Doranc1ec40a0b931
diff --git a/apps/client/src/stylesheets/table.css b/apps/client/src/stylesheets/table.cssindex 0c7f9eb03e..16c67830c1 100644--- a/apps/client/src/stylesheets/table.css+++ b/apps/client/src/stylesheets/table.css@@ -123,6 +123,18 @@border-bottom-color: var(--col-header-arrow-inactive-color);}+.tabulator .tabulator-header .tabulator-col.tabulator-sortable.table-right-aligned-column {+ .tabulator-col-title {+ padding-right: 0;+ padding-left: 25px;+ }++ .tabulator-col-sorter {+ right: auto;+ left: 4px;+ }+}+@media (hover: hover) and (pointer: fine) {.tabulator .tabulator-header .tabulator-col.tabulator-sortable.tabulator-col-sorter-element:hover {background-color: var(--col-header-hover-background-color);diff --git a/apps/client/src/widgets/collections/table/columns.spec.ts b/apps/client/src/widgets/collections/table/columns.spec.tsindex 6cbc7b4b58..179fd51d7a 100644--- a/apps/client/src/widgets/collections/table/columns.spec.ts+++ b/apps/client/src/widgets/collections/table/columns.spec.ts@@ -200,7 +200,7 @@ describe("buildColumnDefinitions — typed columns", () => {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(name)?.split(" ")).toContain("table-numeric-cell");}expect(classOf("text")).toBeUndefined();});@@ -215,7 +215,20 @@ describe("buildColumnDefinitions — typed columns", () => {const columnOf = (name: string) => columns.find((column) => column.field === `labels.${name}`);expect(columnOf("number")).toMatchObject({ hozAlign: "right", headerHozAlign: "right" });+ expect(columnOf("number")?.cssClass?.split(" ")).toContain("table-right-aligned-column");expect(columnOf("date")?.hozAlign).toBeUndefined();+ expect(columnOf("date")?.cssClass?.split(" ")).not.toContain("table-right-aligned-column");+ });++ it("centers the row number column's header over its numbers", () => {+ const [ rowNumberColumn ] = buildColumnDefinitions({+ info: [],+ movableRows: false,+ existingColumnData: undefined,+ rowNumberHint: 1+ });++ expect(rowNumberColumn).toMatchObject({ title: "#", hozAlign: "center", headerHozAlign: "center" });});it("hands a url column's href through the scheme guard rather than linking the value as stored", () => {diff --git a/apps/client/src/widgets/collections/table/columns.tsx b/apps/client/src/widgets/collections/table/columns.tsxindex 72232431ac..5eb68986c9 100644--- a/apps/client/src/widgets/collections/table/columns.tsx+++ b/apps/client/src/widgets/collections/table/columns.tsx@@ -23,6 +23,8 @@ 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";+/** Moves the header's sort arrow to the left, so that a right-aligned title ends where its cells do. */+const RIGHT_ALIGNED_COLUMN_CLASS = "table-right-aligned-column";export interface AttributeDefinitionInformation {name: string;@@ -73,7 +75,7 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {},number: {editor: "number",- cssClass: NUMERIC_CELL_CLASS,+ cssClass: `${NUMERIC_CELL_CLASS} ${RIGHT_ALIGNED_COLUMN_CLASS}`,hozAlign: "right",headerHozAlign: "right",sorter: "number"@@ -166,6 +168,7 @@ export function buildColumnDefinitions({ info, movableRows, existingColumnData,title: "#",headerSort: false,hozAlign: "center",+ headerHozAlign: "center",resizable: false,frozen: true,cssClass: "table-row-number",diff --git a/apps/client/src/widgets/type_widgets/SqlConsole.tsx b/apps/client/src/widgets/type_widgets/SqlConsole.tsxindex 2d7f317f14..9b46f18e79 100644--- a/apps/client/src/widgets/type_widgets/SqlConsole.tsx+++ b/apps/client/src/widgets/type_widgets/SqlConsole.tsx@@ -124,6 +124,8 @@ function SqlResultTable({ rows }: { rows: object[] }) {formatter: "rownum",width: 60,hozAlign: "right",+ headerHozAlign: "right",+ headerSort: false,frozen: true,cssClass: "table-row-number"},