Skip to content

Commit dcac641

Browse files
committed
Added keep length parameter
1 parent a3d1a8b commit dcac641

8 files changed

+75
-4
lines changed

docs/demo.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class="mb-0"
99
:data="laravelData"
1010
:limit="limit"
11+
:keep-length="keepLength"
1112
:show-disabled="showDisabled"
1213
:size="size"
1314
:align="align"
@@ -23,6 +24,7 @@
2324
class="mb-0"
2425
:data="laravelData"
2526
:limit="limit"
27+
:keep-length="keepLength"
2628
:show-disabled="showDisabled"
2729
:size="size"
2830
:align="align"
@@ -36,6 +38,7 @@
3638
<TailwindPagination
3739
:data="laravelData"
3840
:limit="limit"
41+
:keep-length="keepLength"
3942
@pagination-change-page="getResults"
4043
/>
4144
</RenderToIFrame>
@@ -81,6 +84,7 @@ export default {
8184
laravelResourceData: {},
8285
style: 'bootstrap4',
8386
limit: 2,
87+
keepLength: false,
8488
showDisabled: false,
8589
size: 'default',
8690
align: 'left'
@@ -143,6 +147,9 @@ export default {
143147
this.limit = 0;
144148
}
145149
},
150+
keepLength (newVal) {
151+
this.keepLength = Boolean(newVal);
152+
},
146153
},
147154
}
148155
</script>
@@ -155,4 +162,4 @@ iframe {
155162
height: 4rem;
156163
background-color: transparent;
157164
}
158-
</style>
165+
</style>

docs/guide/advanced/renderless-pagination.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Below is an example of how you might use the `RenderlessPagination` component to
1111
<RenderlessPagination
1212
:data="data"
1313
:limit="limit"
14+
:keep-length="keepLength"
1415
@pagination-change-page="onPaginationChangePage"
1516
v-slot="slotProps"
1617
>
@@ -70,6 +71,10 @@ export default {
7071
type: Number,
7172
default: 0
7273
},
74+
keepLength: {
75+
type: Boolean,
76+
default: false
77+
},
7378
},
7479
7580
methods: {
@@ -92,6 +97,10 @@ The `data` prop that was passed to the `RenderlessPagination` component.
9297

9398
The `limit` prop that was passed to the `RenderlessPagination` component.
9499

100+
### keepLength
101+
102+
The `keepLength` prop that was passed to the `RenderlessPagination` component.
103+
95104
### computed
96105

97106
Some computed properties that are used by the `RenderlessPagination` component:
@@ -125,4 +134,4 @@ An object containing the event listeners for the next button:
125134

126135
An function containing the event listeners for a page button. Takes the `page` number as an argument:
127136

128-
* `click` - Event listener for the `click` event
137+
* `click` - Event listener for the `click` event

docs/guide/api/props.md

+5
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ An object containing the structure of a [Laravel paginator](https://laravel.com/
1414

1515
Limit of pages to be rendered. `0` shows all pages (default). `-1` will hide numeric pages and leave only arrow navigation. Any positive integer (e.g. `2`) will define how many pages should be shown on either side of the current page when only a range of pages are shown.
1616

17+
## keepLength
18+
19+
* `Boolean` (optional)
20+
21+
When `true`, the pagination component will keep the same length regardless of the position of the page number. This is useful when you want to keep the pagination component always the same size and not vary at the first or last pages. It does uses the `limit` to determine the length of the pagination component.

src/Bootstrap4Pagination.vue

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<RenderlessPagination
33
:data="data"
44
:limit="limit"
5+
:keep-length="keepLength"
56
@pagination-change-page="onPaginationChangePage"
67
v-slot="slotProps"
78
>
@@ -70,6 +71,10 @@ export default {
7071
type: Number,
7172
default: 0
7273
},
74+
keepLength: {
75+
type: Boolean,
76+
default: false
77+
},
7378
showDisabled: {
7479
type: Boolean,
7580
default: false

src/Bootstrap5Pagination.vue

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<RenderlessPagination
33
:data="data"
44
:limit="limit"
5+
:keep-length="keepLength"
56
@pagination-change-page="onPaginationChangePage"
67
v-slot="slotProps"
78
>
@@ -71,6 +72,10 @@ export default {
7172
type: Boolean,
7273
default: false
7374
},
75+
keepLength: {
76+
type: Boolean,
77+
default: false
78+
},
7479
size: {
7580
type: String,
7681
default: 'default',

src/RenderlessPagination.vue

+22-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export default {
1111
type: Number,
1212
default: 0
1313
},
14+
keepLength: {
15+
type: Boolean,
16+
default: false
17+
},
1418
},
1519
1620
computed: {
@@ -57,16 +61,32 @@ export default {
5761
}
5862
5963
var current = this.currentPage;
64+
var size = this.keepLength;
6065
var last = this.lastPage;
6166
var delta = this.limit;
6267
var left = current - delta;
63-
var right = current + delta + 1;
68+
var right = current + delta;
69+
var leftPad = (delta + 2) * 2;
70+
var rightPad = ((delta + 2) * 2) - 1;
6471
var range = [];
6572
var pages = [];
6673
var l;
6774
6875
for (var i = 1; i <= last; i++) {
69-
if (i === 1 || i === last || (i >= left && i < right)) {
76+
// Item is first or last
77+
if (i === 1 || i === last) {
78+
range.push(i);
79+
}
80+
// Item is within the delta
81+
else if (i >= left && i <= right) {
82+
range.push(i);
83+
}
84+
// Item is before max left padding
85+
else if (size && i < leftPad && current < leftPad - 2) {
86+
range.push(i);
87+
}
88+
// Item is after max right padding
89+
else if (size && i > last - rightPad && current > last - rightPad + 2) {
7090
range.push(i);
7191
}
7292
}

src/TailwindPagination.vue

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<RenderlessPagination
33
:data="data"
44
:limit="limit"
5+
:keep-length="keepLength"
56
@pagination-change-page="onPaginationChangePage"
67
v-slot="slotProps"
78
>
@@ -87,6 +88,10 @@ export default {
8788
type: Number,
8889
default: 0
8990
},
91+
keepLength: {
92+
type: Boolean,
93+
default: false
94+
},
9095
itemClasses: {
9196
type: Array,
9297
default: () => [

src/demo/App.vue

+15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
</select>
2525
</div>
2626
</div>
27+
<div class="row">
28+
<div class="col">
29+
<div class="form-check">
30+
<input class="form-check-input" type="checkbox" id="keep-length" v-model="keepLength">
31+
<label class="form-check-label" for="keep-length">Keep Length</label>
32+
</div>
33+
</div>
34+
</div>
2735
<div class="row">
2836
<div class="col">
2937
<div class="form-check">
@@ -43,6 +51,7 @@
4351
class="mb-0"
4452
:data="laravelData"
4553
:limit="limit"
54+
:keep-length="keepLength"
4655
:show-disabled="showDisabled"
4756
:size="size"
4857
:align="align"
@@ -57,6 +66,7 @@
5766
class="mb-0"
5867
:data="laravelData"
5968
:limit="limit"
69+
:keep-length="keepLength"
6070
:show-disabled="showDisabled"
6171
:size="size"
6272
:align="align"
@@ -69,6 +79,7 @@
6979
<TailwindPagination
7080
:data="laravelData"
7181
:limit="limit"
82+
:keep-length="keepLength"
7283
@pagination-change-page="getResults"
7384
/>
7485
</RenderToIFrame>
@@ -119,6 +130,7 @@ export default {
119130
laravelResourceData: {},
120131
style: 'bootstrap4',
121132
limit: 2,
133+
keepLength: false,
122134
showDisabled: false,
123135
size: 'default',
124136
align: 'left'
@@ -181,6 +193,9 @@ export default {
181193
this.limit = 0;
182194
}
183195
},
196+
keepLength (newVal) {
197+
this.keepLength = Boolean(newVal);
198+
},
184199
},
185200
}
186201
</script>

0 commit comments

Comments
 (0)