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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user