|
16 | 16 | <a class="page-link" href=""> 1 </a> |
17 | 17 | </li> |
18 | 18 | <li class="page-item disabled" v-if="start > 3"> |
19 | | - <a class="page-link" href="">...</a> |
| 19 | + <a class="page-link" href="">…</a> |
20 | 20 | </li> |
21 | 21 | <li class="page-item" v-for="index in range" :key="index" v-bind:class="{ active: (index == page)}" @click.prevent="pageHandler(index)"> |
22 | 22 | <a class="page-link" href="">{{index}}</a> |
23 | 23 | </li> |
24 | 24 | <li class="page-item disabled" v-if="end < totalPages - 2"> |
25 | | - <a class="page-link" href="">...</a> |
| 25 | + <a class="page-link" href="">…</a> |
26 | 26 | </li> |
27 | 27 | <li class="page-item" v-if="end < totalPages - 2" @click.prevent="pageHandler(totalPages)"> |
28 | 28 | <a class="page-link" href=""> {{totalPages}} </a> |
|
31 | 31 |
|
32 | 32 | <template v-else> |
33 | 33 | <li class="page-item disabled"> |
34 | | - <a class="page-link" href="">...</a> |
| 34 | + <a class="page-link" href="">…</a> |
35 | 35 | </li> |
36 | 36 | </template> |
37 | 37 | <li :class="{'disabled' : disableNextButton}" class="page-item" @click.prevent="pageHandler(page+1)"> |
|
58 | 58 | <!-- Number of rows per page ends here --> |
59 | 59 |
|
60 | 60 | <div class="input-group col-sm-2"> |
61 | | - <input type="number" class="form-control" :min="start" :max="totalPages" placeholder="Go to page" @keyup.enter="gotoPage" v-model.number="go_to_page"> |
| 61 | + <input type="number" class="form-control" min="1" step="1" :max="totalPages" placeholder="Go to page" @keyup.enter="gotoPage" v-model.number="go_to_page"> |
62 | 62 | </div> |
63 | 63 | </ul> |
64 | 64 | </nav> |
|
107 | 107 | }, |
108 | 108 | methods: { |
109 | 109 | gotoPage() { |
110 | | - if (this.go_to_page === "") { |
111 | | - return; |
112 | | - } |
113 | | -
|
114 | | - if(this.go_to_page < 1 || this.go_to_page > this.totalPages) { |
115 | | - console.log("invalid page number"); |
| 110 | + if (this.go_to_page === "" || !this.isPositiveInteger(this.go_to_page)) { |
116 | 111 | return; |
117 | 112 | } |
118 | 113 |
|
|
128 | 123 | this.$emit('update:per_page', option); |
129 | 124 | }, |
130 | 125 | calculatePageRange(force = false) { |
| 126 | + //Skip calculating if all pages can be shown |
| 127 | + if (this.totalPages <= this.num_of_visibile_pagination_buttons) { |
| 128 | + this.start = 1; |
| 129 | + this.end = this.totalPages; |
| 130 | + return; |
| 131 | + } |
| 132 | +
|
131 | 133 | //Skip recalculating if the previous and next pages are already visible |
132 | 134 | if (!force && |
133 | 135 | (includes(this.range, this.page - 1) || this.page == 1) && |
|
156 | 158 |
|
157 | 159 | //Handle start underflow |
158 | 160 | this.start = Math.max(this.start, 1); |
| 161 | + }, |
| 162 | + isPositiveInteger(str) { |
| 163 | + return /^\+?(0|[1-9]\d*)$/.test(str); |
159 | 164 | } |
160 | 165 | }, |
161 | 166 | components: { |
|
0 commit comments