From 72a2390dc677cf4607d9b81a746cf7a8894e4965 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?=
<80620802+burakboduroglu@users.noreply.github.com>
Date: Thu, 30 Jul 2026 08:11:51 +0300
Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=93=8A=20align=20table=20headers?=
=?UTF-8?q?=20with=20cells,=20fix=20page-size=20+=20inline=20averages=20-?=
=?UTF-8?q?=20drop=20text-align=20from=20`.data-table=20th`:=20the=20`.dat?=
=?UTF-8?q?a-table=20th`=20rule=20=20=20out-specified=20per-column=20text-?=
=?UTF-8?q?right/center=20utilities=20and=20forced=20every=20=20=20header?=
=?UTF-8?q?=20left=20while=20cells=20aligned=20fine=20(header/cell=20misma?=
=?UTF-8?q?tch)=20-=20add=20`meta.align`=20to=20DataTable=20as=20the=20sin?=
=?UTF-8?q?gle=20source=20of=20alignment=20for=20both=20=20=20head=20and?=
=?UTF-8?q?=20cell;=20sort=20button=20offsets=20by=20align=20instead=20of?=
=?UTF-8?q?=20a=20blanket=20-ml-3=20-=20migrate=20numeric=20columns=20(mar?=
=?UTF-8?q?ks/attendance/homework=20reports,=20my-students,=20=20=20studen?=
=?UTF-8?q?t-marks)=20off=20ad-hoc=20header=20spans=20to=20meta.align=20-?=
=?UTF-8?q?=20add=20opt-in=20`meta.stickyLeft`=20frozen-left=20column=20+?=
=?UTF-8?q?=20`meta.divider`=20and=20a=20=20=20directional=20border/shadow?=
=?UTF-8?q?=20seam;=20rename=20sticky-right=20=20=20classes;=20clearer=20s?=
=?UTF-8?q?ort=20icons=20(ChevronsUpDown=20=E2=86=92=20ArrowUp/ArrowDown)?=
=?UTF-8?q?=20-=20TablePagination:=20always=20include=20the=20active=20pag?=
=?UTF-8?q?e=20size=20in=20the=20options=20so=20=20=20the=20selector=20sho?=
=?UTF-8?q?ws=20a=20value=20instead=20of=20blank=20on=20non-standard=20siz?=
=?UTF-8?q?es=20-=20standardize=20the=20generic=2012-row=20list=20default?=
=?UTF-8?q?=20to=2010=20across=20pages=20-=20student-marks:=20re-materiali?=
=?UTF-8?q?ze=20table=20data=20when=20the=20per-student=20marks=20=20=20re?=
=?UTF-8?q?source=20resolves=20so=20the=20inline=20average=20fills=20in=20?=
=?UTF-8?q?without=20needing=20a=20sort?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../attendance/attendance-report-view.tsx | 13 ++--
.../homework/homework-report-view.tsx | 2 +-
src/components/marks/marks-report-view.tsx | 9 +--
src/components/ui/data-table.test.tsx | 27 ++++++-
src/components/ui/data-table.tsx | 71 +++++++++++++++----
src/components/ui/icons.tsx | 27 +++++++
src/components/ui/table-pagination.tsx | 7 +-
src/index.css | 33 +++++++--
src/pages/courses-page.tsx | 2 +-
src/pages/exams-page.tsx | 2 +-
src/pages/homework-page.tsx | 2 +-
src/pages/meals-page.tsx | 2 +-
src/pages/my-students-page.tsx | 8 +--
src/pages/notes-page.tsx | 2 +-
src/pages/payment-statement-page.tsx | 2 +-
src/pages/payments-page.tsx | 2 +-
src/pages/question-bank-page.tsx | 2 +-
src/pages/staff-work-page.tsx | 2 +-
src/pages/student-attendance-page.tsx | 2 +-
src/pages/student-marks-page.tsx | 16 +++--
src/pages/student-pomodoro-page.tsx | 2 +-
src/pages/terms-page.tsx | 2 +-
22 files changed, 183 insertions(+), 54 deletions(-)
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 (