From f11cc7c1d34d76b3b9dfb3ded64911d7c0d64fbf Mon Sep 17 00:00:00 2001 From: Egbert Bouman Date: Mon, 16 Dec 2024 10:53:35 +0100 Subject: [PATCH] Fix pagination when displaying trees --- src/tribler/ui/src/components/ui/simple-table.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tribler/ui/src/components/ui/simple-table.tsx b/src/tribler/ui/src/components/ui/simple-table.tsx index 980e3e65f0..2b8840892a 100644 --- a/src/tribler/ui/src/components/ui/simple-table.tsx +++ b/src/tribler/ui/src/components/ui/simple-table.tsx @@ -140,8 +140,14 @@ function SimpleTable({ onSortingChange: setSorting, getSubRows: (row: any) => row?.subRows, getRowId: rowId, + autoResetPageIndex: false, }); + // If we're on an empty page, reset the pageIndex to 0 + if (table.getRowModel().rows.length == 0 && table.getExpandedRowModel().rows.length != 0) { + setPagination(p => ({ ...p, pageIndex: 0 })); + } + const { t } = useTranslation(); useEffect(() => { @@ -248,7 +254,7 @@ function SimpleTable({ function Pagination({ table }: React.PropsWithChildren<{ table: ReactTable }>) { const pageIndex = table.getState().pagination.pageIndex; const pageSize = table.getState().pagination.pageSize; - const rowCount = table.getCoreRowModel().rows.length; + const rowCount = table.getExpandedRowModel().rows.length; const { t } = useTranslation();