Mishig
commited on
Commit
•
2468399
1
Parent(s):
3890de7
[Assistnats] Fix pagination numTotalPages (#780)
Browse files* [Assistnats] Fix pagination numTotalPages
* morereactivity
src/lib/components/Pagination.svelte
CHANGED
@@ -8,9 +8,9 @@
|
|
8 |
|
9 |
const ELLIPSIS_IDX = -1 as const;
|
10 |
|
11 |
-
|
12 |
$: pageIndex = parseInt($page.url.searchParams.get("p") ?? "0");
|
13 |
-
$: pageIndexes = getPageIndexes(pageIndex);
|
14 |
|
15 |
function getHref(pageIdx: number) {
|
16 |
const newUrl = new URL($page.url);
|
@@ -18,13 +18,13 @@
|
|
18 |
return newUrl.toString();
|
19 |
}
|
20 |
|
21 |
-
function getPageIndexes(pageIdx: number) {
|
22 |
let pageIdxs: number[] = [];
|
23 |
|
24 |
const NUM_EXTRA_BUTTONS = 2; // The number of page links to show on either side of the current page link.
|
25 |
|
26 |
const minIdx = 0;
|
27 |
-
const maxIdx =
|
28 |
|
29 |
pageIdxs = [pageIdx];
|
30 |
|
|
|
8 |
|
9 |
const ELLIPSIS_IDX = -1 as const;
|
10 |
|
11 |
+
$: numTotalPages = Math.ceil(numTotalItems / numItemsPerPage);
|
12 |
$: pageIndex = parseInt($page.url.searchParams.get("p") ?? "0");
|
13 |
+
$: pageIndexes = getPageIndexes(pageIndex, numTotalPages);
|
14 |
|
15 |
function getHref(pageIdx: number) {
|
16 |
const newUrl = new URL($page.url);
|
|
|
18 |
return newUrl.toString();
|
19 |
}
|
20 |
|
21 |
+
function getPageIndexes(pageIdx: number, nTotalPages: number) {
|
22 |
let pageIdxs: number[] = [];
|
23 |
|
24 |
const NUM_EXTRA_BUTTONS = 2; // The number of page links to show on either side of the current page link.
|
25 |
|
26 |
const minIdx = 0;
|
27 |
+
const maxIdx = nTotalPages - 1;
|
28 |
|
29 |
pageIdxs = [pageIdx];
|
30 |
|