From 0ce9d6b9cd8438d3e94d6268ee422a4b43378eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Fri, 18 Sep 2026 12:07:16 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=E2=86=95=EF=B8=8F=20server-paged=20tabl?= =?UTF-8?q?es=20stop=20sorting=20a=20single=20page=20-=20DataTable=20sorti?= =?UTF-8?q?ng=20is=20client-side=20and=20the=20backend=20takes=20no=20sort?= =?UTF-8?q?=20=20=20parameter=20(checked=20against=20the=20live=20OpenAPI)?= =?UTF-8?q?,=20so=20with=20manualPagination=20=20=20a=20header=20sort=20re?= =?UTF-8?q?ordered=20only=20the=20visible=20page=20while=20implying=20the?= =?UTF-8?q?=20whole=20=20=20list;=20it=20is=20now=20off=20there=20unless?= =?UTF-8?q?=20a=20caller=20opts=20in=20-=20affects=20the=20payments=20and?= =?UTF-8?q?=20question=20bank=20tables=20-=20test:=20header=20sort=20offer?= =?UTF-8?q?ed=20for=20client=20paging,=20not=20for=20server=20paging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ui/data-table.test.tsx | 23 +++++++++++++++++++++++ src/components/ui/data-table.tsx | 8 ++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) 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}; }