diff --git a/src/components/ui/data-table.test.tsx b/src/components/ui/data-table.test.tsx index 80fb209..661dea2 100644 --- a/src/components/ui/data-table.test.tsx +++ b/src/components/ui/data-table.test.tsx @@ -170,3 +170,26 @@ test("a search that matches nothing says so and clears back to the list", () => fireEvent.click(within(screen.getByRole("table")).getByRole("button", { name: /Clear search|Aramayı temizle/ })); expect(screen.getByText("Ada")).toBeTruthy(); }); + +test("a server-paged table offers no header sort, since it could only sort one page", () => { + const sortable: ColumnDef[] = [{ accessorKey: "name", header: "Name" }]; + const { unmount } = render(() => ( + + + + )); + expect(screen.getByRole("button", { name: /Name/ })).toBeTruthy(); + unmount(); + + render(() => ( + + {} }} + /> + + )); + expect(screen.queryByRole("button", { name: /^Name/ })).toBeNull(); +}); diff --git a/src/components/ui/data-table.tsx b/src/components/ui/data-table.tsx index 44028ea..de16745 100644 --- a/src/components/ui/data-table.tsx +++ b/src/components/ui/data-table.tsx @@ -95,6 +95,10 @@ export function DataTable(props: DataTableProps props.searchValue ?? search(); + // Sorting is client-side only, and the backend takes no sort parameter: on + // a server-paged table it would reorder the visible page alone while the + // header claimed the whole list. Off there unless a caller opts in. + const sortingEnabled = () => props.enableSorting ?? !props.manualPagination; const tableData = () => { const query = searchValue().trim(); if (!query || !props.searchPredicate) return props.data; @@ -107,7 +111,7 @@ export function DataTable(props: DataTableProps(props: DataTableProps[number]["headers"][number]) => { const content = flexRender(header.column.columnDef.header, header.getContext()); const align = alignOf(header.column); - if (!(props.enableSorting ?? true) || !header.column.getCanSort()) { + if (!sortingEnabled() || !header.column.getCanSort()) { // The th already carries alignClass; the block span makes text-align resolve. return {content}; }