fix table pagination

This commit is contained in:
Karol Wypchlo 2021-02-10 23:12:19 +01:00
parent 5b9a9932bb
commit 7f5451f9a9
1 changed files with 5 additions and 5 deletions

View File

@ -22,11 +22,11 @@ function Button({ children, disabled, className, ...props }) {
}
export default function Table({ items, count, headers, actions, offset, setOffset, pageSize = 10 }) {
// useEffect(() => {
// if (offset + pageSize > count) setOffset(Math.floor(count / pageSize));
// else if (offset < 0) setOffset(0);
// else if (offset % pageSize) setOffset(offset - (offset % pageSize));
// }, [offset, pageSize, setOffset]);
useEffect(() => {
if (offset < 0) setOffset(0);
else if (offset >= count) setOffset(count - (count % pageSize));
else if (offset % pageSize) setOffset(offset - (offset % pageSize));
}, [offset, pageSize, setOffset]);
if (!items) {
return <div className="text-center">no entries</div>;