fix: pagination

This commit is contained in:
Torsten Dittmann
2022-07-11 12:32:09 +02:00
parent 37749453e4
commit 5529352f2c
+3 -7
View File
@@ -5,15 +5,15 @@
export let offset: number;
const dispatch = createEventDispatcher();
const totalPages = Math.ceil(sum / limit);
let currentPage = Math.floor(offset / limit + 1);
$: totalPages = Math.ceil(sum / limit);
$: currentPage = Math.floor(offset / limit + 1);
$: pages = pagination(currentPage, totalPages);
function handleOptionClick(page: number) {
if (currentPage !== page) {
offset = limit * (page - 1);
currentPage = page;
dispatch('change');
pages = pagination(currentPage, totalPages);
}
}
@@ -22,17 +22,13 @@
currentPage += 1;
offset = limit * (currentPage - 1);
dispatch('change');
pages = pagination(currentPage, totalPages);
} else if (direction === 'prev' && currentPage > 1) {
currentPage -= 1;
offset = limit * (currentPage - 1);
dispatch('change');
pages = pagination(currentPage, totalPages);
}
}
let pages = pagination(currentPage, totalPages);
function pagination(page: number, total: number) {
const pagesShown = 5;
const start = Math.max(