forge
Explore
Log in

Don't you dare go Hollow

🧱 render a display column's own cell instead of the empty dash

Browse files at this commit

a616723d366097875739c85652bc925be4c4cc34Burak BoduroğluParent: c836700
  • fix
    • 🧱 render a display column's own cell instead of the empty dash
Show full message
fix: 🧱 render a display column's own cell instead of the empty dash
- DataTable replaced a cell with "-" whenever cell.getValue() was empty,
  without ever calling the column's own render function. A display column
  (no accessorFn/accessorKey) has no value to be empty — getValue() is
  always undefined — so every column that draws itself from row.original
  silently rendered a dash
- the payments student roster showed "-" on every row while the backend
  was returning full display names
- the empty-cell fallback now applies only to columns that actually carry
  a value; the "actions"/"update"/"select" id allowlist stays as a second
  guard
src/components/ui/data-table.test.tsxmodified+18 -0
@@ -101,3 +101,21 @@ test("shows the pagination footer on a single page", () => {
101 expect((screen.getByRole("button", { name: "Previous" }) as HTMLButtonElement).disabled).toBe(true);101 expect((screen.getByRole("button", { name: "Previous" }) as HTMLButtonElement).disabled).toBe(true);
102 expect((screen.getByRole("button", { name: "Next" }) as HTMLButtonElement).disabled).toBe(true);102 expect((screen.getByRole("button", { name: "Next" }) as HTMLButtonElement).disabled).toBe(true);
103 });103 });
104+
105+test("a display column renders its own cell instead of the empty dash", () => {
106+ // A column with no accessorFn has no value to be empty, so the empty-cell
107+ // fallback must not swallow its render function.
108+ render(() => (
109+ <PreferencesProvider>
110+ <DataTable
111+ columns={[
112+ { accessorKey: "name", header: "Name" },
113+ { id: "label", header: "Label", cell: (c) => `#${c.row.original.name}` },
114+ ] as ColumnDef<Row>[]}
115+ data={[{ name: "ada" }]}
116+ />
117+ </PreferencesProvider>
118+ ));
119+
120+ expect(screen.getByText("#ada")).toBeTruthy();
121+});
src/components/ui/data-table.tsxmodified+7 -1
@@ -355,7 +355,13 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData,
355 const val = cell.getValue();355 const val = cell.getValue();
356 const isText = typeof val === "string" || typeof val === "number";356 const isText = typeof val === "string" || typeof val === "number";
357 const isSystemColumn = ["actions", "update", "select"].includes(cell.column.id);357 const isSystemColumn = ["actions", "update", "select"].includes(cell.column.id);
358- const isEmpty = !isSystemColumn && (val == null || val === "");358+ // A display column (no accessorFn/accessorKey) has no
359+ // value to be empty — getValue() is always undefined —
360+ // so it must render its own `cell`, or a column that
361+ // draws itself from row.original silently shows "-".
362+ const isDisplayColumn = cell.column.accessorFn == null;
363+ const isEmpty =
364+ !isSystemColumn && !isDisplayColumn && (val == null || val === "");
359 365
360 return (366 return (
361 <TableCell367 <TableCell