fix(ui): prioritize providedRowCount in useTable hook

Changed the row count calculation in the useTable hook to prioritize
the providedRowCount prop over data.length. This ensures accurate
row count values in server-side pagination scenarios where the total
number of rows differs from the current page's data length.

Signed-off-by: Johan Persson <johanopersson@gmail.com>
This commit is contained in:
Johan Persson
2025-11-18 17:35:58 +01:00
parent 100b0806b6
commit fe7c751344
2 changed files with 7 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/ui': patch
---
Fixed `useTable` hook to prioritize `providedRowCount` over data length for accurate row count in server-side pagination scenarios.
@@ -50,8 +50,8 @@ export function useTable<T = any>(
const isControlled =
controlledOffset !== undefined || controlledPageSize !== undefined;
// Calculate row count from data or use provided value
const rowCount = data?.length ?? providedRowCount ?? 0;
// Use providedRowCount if passed, otherwise fallback to data length
const rowCount = providedRowCount ?? data?.length ?? 0;
// Internal state for uncontrolled mode
const [internalOffset, setInternalOffset] = useState(defaultOffset);