diff --git a/src/components/attendance/attendance-report-view.tsx b/src/components/attendance/attendance-report-view.tsx
index 363f35f..b26698d 100644
--- a/src/components/attendance/attendance-report-view.tsx
+++ b/src/components/attendance/attendance-report-view.tsx
@@ -33,16 +33,17 @@ export function AttendanceReportView(props: { report: AttendanceReport; compact?
{
id: "course",
header: t("nav.courses"),
+ meta: { stickyLeft: true },
cell: (cell) => (
{cell.row.original.course.title}
),
},
- ...ATTENDANCE_STATUSES.map((status) => ({
+ ...ATTENDANCE_STATUSES.map((status, index) => ({
id: status.value,
header: () => {compact() ? t(status.key).slice(0, 1) : t(status.key)},
- meta: { headerClass: "text-right", cellClass: "text-right" },
+ meta: { align: "right" as const, divider: index === 0 ? ("left" as const) : undefined },
cell: (cell) => (
{cell.row.original.counts[status.value]}
@@ -51,14 +52,14 @@ export function AttendanceReportView(props: { report: AttendanceReport; compact?
} satisfies ColumnDef)),
{
id: "total",
- header: () => {compact() ? "Σ" : t("common.all")},
- meta: { cellClass: "mono text-right" },
+ header: () => {compact() ? "Σ" : t("common.all")},
+ meta: { align: "right", cellClass: "mono" },
cell: (cell) => cell.row.original.counts.total,
},
{
id: "rate",
- header: () => %,
- meta: { cellClass: "mono text-right font-semibold" },
+ header: () => %,
+ meta: { align: "right", cellClass: "mono font-semibold" },
cell: (cell) => percent(cell.row.original.counts.rate),
},
]);
diff --git a/src/components/homework/homework-report-view.tsx b/src/components/homework/homework-report-view.tsx
index b10ac7d..55b2386 100644
--- a/src/components/homework/homework-report-view.tsx
+++ b/src/components/homework/homework-report-view.tsx
@@ -56,7 +56,7 @@ export function HomeworkReportView(props: { userId: string }) {
{
id: "mark",
header: t("form.mark"),
- meta: { cellClass: "text-right font-medium tabular-nums" },
+ meta: { align: "right", cellClass: "font-medium tabular-nums" },
cell: (cell) => cell.row.original.result?.mark ?? "—",
},
{
diff --git a/src/components/marks/marks-report-view.tsx b/src/components/marks/marks-report-view.tsx
index e36f3ad..d1e1925 100644
--- a/src/components/marks/marks-report-view.tsx
+++ b/src/components/marks/marks-report-view.tsx
@@ -33,6 +33,7 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean
{
accessorKey: "title",
header: t("marks.exam"),
+ meta: { stickyLeft: true },
cell: (cell) => (
@@ -54,14 +55,14 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean
},
{
id: "weight",
- header: () => {t("marks.weight")},
- meta: { cellClass: "mono text-right" },
+ header: t("marks.weight"),
+ meta: { align: "right", divider: "left", cellClass: "mono" },
cell: (cell) => examWeight(cell.row.original, settings()?.exam_kinds) ?? "—",
},
{
accessorKey: "mark",
- header: () => {t("marks.mark")},
- meta: { cellClass: "mono text-right font-semibold" },
+ header: t("marks.mark"),
+ meta: { align: "right", cellClass: "mono font-semibold" },
cell: (cell) => markWithGrade(cell.row.original.mark, cell.row.original.grade),
},
]);
diff --git a/src/components/ui/data-table.test.tsx b/src/components/ui/data-table.test.tsx
index 8208512..af5f955 100644
--- a/src/components/ui/data-table.test.tsx
+++ b/src/components/ui/data-table.test.tsx
@@ -40,10 +40,33 @@ test("keeps only the rightmost action column sticky", () => {
));
const actionsHeader = screen.getByRole("columnheader", { name: "Actions" });
- expect(actionsHeader.classList).toContain("table-sticky-head");
+ expect(actionsHeader.classList).toContain("table-sticky-head-right");
expect(actionsHeader.classList).toContain("z-30");
const roleHeader = screen.getAllByRole("columnheader").find((header) => header.textContent?.startsWith("Role"));
- expect(roleHeader?.classList).not.toContain("table-sticky-head");
+ expect(roleHeader?.classList).not.toContain("table-sticky-head-right");
+});
+
+test("freezes the meta.stickyLeft column and aligns head + cell together", () => {
+ const alignedColumns: ColumnDef[] = [
+ { accessorKey: "name", header: "Name", meta: { stickyLeft: true } },
+ { accessorKey: "role", header: "Role", meta: { align: "right" } },
+ ];
+ render(() => (
+
+
+
+ ));
+
+ const headers = screen.getAllByRole("columnheader");
+ const nameHeader = headers.find((header) => header.textContent?.startsWith("Name"));
+ expect(nameHeader?.classList).toContain("table-sticky-head-left");
+ expect(nameHeader?.classList).toContain("left-0");
+
+ const roleHeader = headers.find((header) => header.textContent?.startsWith("Role"));
+ const roleCell = screen.getByRole("cell", { name: "Admin" });
+ // Same alignment class on head and cell so columns never drift apart.
+ expect(roleHeader?.classList).toContain("text-right");
+ expect(roleCell.classList).toContain("text-right");
});
test("paginates tables by default", () => {
diff --git a/src/components/ui/data-table.tsx b/src/components/ui/data-table.tsx
index b7d9724..1a027a2 100644
--- a/src/components/ui/data-table.tsx
+++ b/src/components/ui/data-table.tsx
@@ -19,7 +19,7 @@ import { Button } from "@/components/ui/button";
import { DataTableSearch } from "@/components/ui/data-table-search";
import { DataTableViewMenu, type ViewMenuColumn } from "@/components/ui/data-table-view-menu";
import { TablePagination } from "@/components/ui/table-pagination";
-import { IconChevronDown } from "@/components/ui/icons";
+import { IconArrowDown, IconArrowUp, IconChevronsUpDown } from "@/components/ui/icons";
import { cn } from "@/lib/cn";
import { createTablePreferences } from "@/lib/table-preferences";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
@@ -30,6 +30,12 @@ declare module "@tanstack/solid-table" {
headerClass?: string;
cellClass?: string;
label?: string;
+ /** Header + cell horizontal alignment. Applied to both so they never drift apart. */
+ align?: "left" | "center" | "right";
+ /** Freeze this column to the left edge on horizontal scroll (fintables-style). */
+ stickyLeft?: boolean;
+ /** Vertical divider on the given edge — separates frozen label from metric columns. */
+ divider?: "left" | "right";
}
}
@@ -70,6 +76,8 @@ export type DataTableProps = {
const resolveUpdater = (updater: Updater, old: T): T =>
typeof updater === "function" ? (updater as (value: T) => T)(old) : updater;
+const alignClass = { left: "text-left", center: "text-center", right: "text-right" } as const;
+
export function DataTable(props: DataTableProps) {
const t = useT();
const paginationEnabled = props.enablePagination ?? true;
@@ -129,11 +137,27 @@ export function DataTable(props: DataTableProps columnId === "actions" || columnId === "update";
- const stickyLocked = (columnId: string) =>
+ const stickyRightLocked = (columnId: string) =>
columnId === "actions" || (columnId === "update" && table.getColumn("actions") == null);
- const actionColumnClass = (columnId: string) => stickyLocked(columnId) ? "w-28 min-w-28 px-2 text-center whitespace-nowrap" : undefined;
- const stickyHeadClass = (columnId: string) => stickyLocked(columnId) ? "table-sticky-head sticky right-0 z-30" : undefined;
- const stickyCellClass = (columnId: string) => stickyLocked(columnId) ? "table-sticky-cell sticky right-0 z-10" : undefined;
+ const isStickyLeft = (column: Column) => column.columnDef.meta?.stickyLeft === true;
+ const alignOf = (column: Column) => column.columnDef.meta?.align ?? "left";
+ const dividerClass = (column: Column) => {
+ const divider = column.columnDef.meta?.divider;
+ return divider === "left" ? "border-l border-border/70" : divider === "right" ? "border-r border-border/70" : undefined;
+ };
+ const actionColumnClass = (columnId: string) => stickyRightLocked(columnId) ? "w-28 min-w-28 px-2 text-center whitespace-nowrap" : undefined;
+ const stickyHeadClass = (column: Column) =>
+ isStickyLeft(column)
+ ? "table-sticky-head-left sticky left-0 z-30"
+ : stickyRightLocked(column.id)
+ ? "table-sticky-head-right sticky right-0 z-30"
+ : undefined;
+ const stickyCellClass = (column: Column) =>
+ isStickyLeft(column)
+ ? "table-sticky-left sticky left-0 z-10"
+ : stickyRightLocked(column.id)
+ ? "table-sticky-right sticky right-0 z-10"
+ : undefined;
const hideableColumns = () => table.getAllColumns().filter((column) => column.getCanHide() && !hiddenLocked(column.id));
const columnLabel = (column: Column) => {
const header = column.columnDef.header;
@@ -149,7 +173,7 @@ export function DataTable(props: DataTableProps Math.max(1, table.getVisibleLeafColumns().length);
const tableWidth = () =>
table.getVisibleLeafColumns().reduce(
- (total, column) => total + (stickyLocked(column.id) ? 112 : column.getSize()),
+ (total, column) => total + (stickyRightLocked(column.id) ? 112 : column.getSize()),
0,
);
const showColumnMenu = () => (props.enableColumnVisibility ?? true) && hideableColumns().length > 0;
@@ -182,18 +206,33 @@ export function DataTable(props: DataTableProps[number]["headers"][number]) => {
const content = flexRender(header.column.columnDef.header, header.getContext());
- if (!(props.enableSorting ?? true) || !header.column.getCanSort()) return content;
+ const align = alignOf(header.column);
+ if (!(props.enableSorting ?? true) || !header.column.getCanSort()) {
+ // The th already carries alignClass; the block span makes text-align resolve.
+ return {content};
+ }
const sorted = () => header.column.getIsSorted();
return (
);
};
@@ -257,14 +296,16 @@ export function DataTable(props: DataTableProps
{renderHeader(header)}
-
+
(props: DataTableProps
(
{flexRender(cell.column.columnDef.cell, cell.getContext())}
diff --git a/src/components/ui/icons.tsx b/src/components/ui/icons.tsx
index c4406d3..ff89e06 100644
--- a/src/components/ui/icons.tsx
+++ b/src/components/ui/icons.tsx
@@ -345,6 +345,33 @@ export function IconChevronDown(props: IconProps) {
);
}
+export function IconArrowUp(props: IconProps) {
+ return (
+
+ );
+}
+
+export function IconArrowDown(props: IconProps) {
+ return (
+
+ );
+}
+
+export function IconChevronsUpDown(props: IconProps) {
+ return (
+
+ );
+}
+
export function IconHome(props: IconProps) {
return (