Skip to content

Commit 67be4a3

Browse files
committed
fix: pagination page numbering Issue #34
1 parent 935361f commit 67be4a3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

html/classhelper.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,15 +536,24 @@ class ClassHelper extends HTMLElement {
536536
return fragment;
537537
}
538538

539-
getPaginationFragment(prevUrl, nextUrl, index, size) {
539+
getPaginationFragment(prevUrl, nextUrl, index, size, total) {
540540
const fragment = document.createDocumentFragment();
541541

542542
const container = document.createElement("div");
543543
container.id = "popup-pagination";
544544
container.classList.add("popup-pagination");
545545

546546
const info = document.createElement('span');
547-
info.textContent = `${1 + (parseInt(index) - 1) * parseInt(size)}..${parseInt(index) * parseInt(size)}`;
547+
548+
const startNumber = (parseInt(index) - 1) * parseInt(size) + 1;
549+
let endNumber;
550+
if (total < size) {
551+
endNumber = startNumber + total - 1;
552+
} else {
553+
endNumber = parseInt(index) * parseInt(size);
554+
}
555+
556+
info.textContent = `${startNumber} - ${endNumber}`;
548557

549558
const prev = document.createElement("button");
550559
prev.innerHTML = ClassHelper.translations["Prev"];
@@ -788,7 +797,7 @@ class ClassHelper extends HTMLElement {
788797
popupBody.appendChild(searchFrag);
789798
}
790799

791-
const paginationFrag = this.getPaginationFragment(prevPageURL, nextPageURL, props.pageIndex, props.pageSize);
800+
const paginationFrag = this.getPaginationFragment(prevPageURL, nextPageURL, props.pageIndex, props.pageSize, data.collection.length);
792801
popupBody.appendChild(paginationFrag);
793802

794803
const tableFrag = this.getTableFragment(props.fields, data.collection, preSelectedValues);
@@ -900,7 +909,7 @@ class ClassHelper extends HTMLElement {
900909
const pageIndex = selfPageURL.searchParams.get("@page_index");
901910

902911
const oldPaginationFrag = popupDocument.getElementById("popup-pagination");
903-
const newPaginationFrag = this.getPaginationFragment(prevPageURL, nextPageURL, pageIndex, props.pageSize);
912+
const newPaginationFrag = this.getPaginationFragment(prevPageURL, nextPageURL, pageIndex, props.pageSize, data.collection.length);
904913
popupBody.replaceChild(newPaginationFrag, oldPaginationFrag);
905914

906915
let oldTableFrag = popupDocument.getElementById("popup-tablediv");
@@ -964,7 +973,7 @@ class ClassHelper extends HTMLElement {
964973
const oldPaginationFrag = popupDocument.getElementById("popup-pagination");
965974
let newPaginationFrag;
966975
if (prevPageURL || nextPageURL) {
967-
newPaginationFrag = this.getPaginationFragment(prevPageURL, nextPageURL, pageIndex, props.pageSize);
976+
newPaginationFrag = this.getPaginationFragment(prevPageURL, nextPageURL, pageIndex, props.pageSize, data.collection.length);
968977
} else {
969978
newPaginationFrag = popupDocument.createElement("div");
970979
newPaginationFrag.id = "popup-pagination";

0 commit comments

Comments
 (0)