Fix Canon DataTable.Pagination to count issue.

Fixes an issue where the pagination component would not consider the
row count when calculating the `from - to of totalCount` string. This
would result in strings like `21-30 of 24`.

Signed-off-by: Johan Persson <johanopersson@gmail.com>
This commit is contained in:
Johan Persson
2025-04-22 16:16:31 +02:00
parent 6c2c6cdbe8
commit 206ffbe99d
2 changed files with 12 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/canon': patch
---
Fixed an issue with Canon's DataTable.Pagination component showing the wrong number for the "to" count.
@@ -32,6 +32,12 @@ const DataTablePagination = forwardRef(
const { table } = useDataTable();
const pageIndex = table?.getState().pagination.pageIndex;
const pageSize = table?.getState().pagination.pageSize;
const rowCount = table?.getRowCount();
const fromCount = (pageIndex ?? 0) * (pageSize ?? 10) + 1;
const toCount = Math.min(
((pageIndex ?? 0) + 1) * (pageSize ?? 10),
rowCount,
);
return (
<div
@@ -63,9 +69,7 @@ const DataTablePagination = forwardRef(
)}
</div>
<div className="canon-DataTablePagination--right">
<Text variant="body">{`${(pageIndex ?? 0) * (pageSize ?? 10) + 1} - ${
((pageIndex ?? 0) + 1) * (pageSize ?? 10)
} of ${table?.getRowCount()}`}</Text>
<Text variant="body">{`${fromCount} - ${toCount} of ${rowCount}`}</Text>
<IconButton
variant="secondary"
size="small"