Skip to content

Commit b03f6a0

Browse files
committed
prevent recalculating of page range, if the preceding and following pages of the target page are already visible in pagination
1 parent 286c0af commit b03f6a0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/Pagination.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@
128128
this.$emit('update:per_page', option);
129129
},
130130
calculatePageRange(force = false) {
131-
//Current page is the start page plus 1
131+
//Skip recalculating if the previous and next pages are already visible
132+
if (!force &&
133+
(includes(this.range, this.page - 1) || this.page == 1) &&
134+
(includes(this.range, this.page + 1) || this.page == this.totalPages)
135+
) { return; }
136+
137+
//Current page is the start page minus one
132138
this.start = (this.page == 1) ? 1 : this.page - 1;
133139
134140
//Reserved entries: firstpage, ellipsis (2x), prev. page, last page, current page
@@ -143,7 +149,6 @@
143149
144150
//If the user navigates on the last two pages or out of bounds, we can shift down start
145151
//This will also handle end overflow, substract 2 for ellipsis and last page
146-
console.log(this.end);
147152
if (this.end >= this.totalPages - 2) {
148153
this.start -= this.end - (this.totalPages - 2);
149154
this.end = this.totalPages;

0 commit comments

Comments
 (0)