🧱 render a display column's own cell instead of the empty dash
Browse files at this commita616723d366097875739c85652bc925be4c4cc34Parent: c836700- fix
- 🧱 render a display column's own cell instead of the empty dash
2 changed files +25 -1
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 | <TableCell | 367 | <TableCell |