1- {% if is_paginated %}
2- < nav class ="pagination is-centered " role ="navigation " aria-label ="pagination ">
3- {% if page_obj.has_previous %}
4- < a href ="?page={{ page_obj.previous_page_number }}&search={{ search|urlencode }}&page_size={{ page_obj.paginator.per_page }} "
5- class ="pagination-previous "> Previous</ a >
6- {% else %}
7- < span class ="pagination-previous " disabled > Previous</ span >
8- {% endif %}
1+ < div class ="pagination-controls mb-4 ">
2+ < div class ="is-flex is-justify-content-center mb-3 ">
3+ < div class ="select is-small {% if total_count < current_page_size %}is-disabled{% endif %} ">
4+ < select onchange ="handlePageSizeChange(this.value) "
5+ {% if total_count < current _page_size %}disabled ="disabled "{% endif %} >
6+ {% for choice in page_size_choices %}
7+ < option value ="{{ choice.value }} "
8+ {% if choice.value == current_page_size %}selected{% endif %} >
9+ {{ choice.label }}
10+ </ option >
11+ {% endfor %}
12+ </ select >
13+ </ div >
14+ </ div >
915
10- {% if page_obj.has_next %}
11- < a href ="?page={{ page_obj.next_page_number }}&search={{ search|urlencode }}&page_size={{ page_obj.paginator.per_page }} "
12- class ="pagination-next "> Next</ a >
13- {% else %}
14- < span class ="pagination-next " disabled > Next</ span >
15- {% endif %}
16+ {% if page_obj.paginator.num_pages > 1 %}
17+ < nav class ="pagination is-centered " role ="navigation " aria-label ="pagination ">
18+ {% if page_obj.has_previous %}
19+ < a href ="?page={{ page_obj.previous_page_number }}&search={{ search|urlencode }}&page_size={{ current_page_size }} "
20+ class ="pagination-previous "> Previous</ a >
21+ {% else %}
22+ < button class ="pagination-previous " disabled > Previous</ button >
23+ {% endif %}
1624
17- < ul class ="pagination-list ">
18- {% if page_obj.number > 1 %}
19- < li >
20- < a href ="?page=1&search={{ search|urlencode }}&page_size={{ page_obj.paginator.per_page }} "
21- class ="pagination-link " aria-label ="Page 1 "> 1</ a >
22- </ li >
23- {% if page_obj.number > 4 %}
24- < li > < span class ="pagination-ellipsis "> …</ span > </ li >
25- {% endif %}
25+ {% if page_obj.has_next %}
26+ < a href ="?page={{ page_obj.next_page_number }}&search={{ search|urlencode }}&page_size={{ current_page_size }} "
27+ class ="pagination-next "> Next</ a >
28+ {% else %}
29+ < button class ="pagination-next " disabled > Next</ button >
2630 {% endif %}
2731
28- {% for i in page_obj.paginator.page_range %}
29- {% if i > 1 and i < page _obj.paginator.num_pages %}
30- {% if i > = page_obj.number|add:"-3" and i < = page_obj.number|add:"3" %}
32+ < ul class ="pagination-list ">
33+ {% for page_num in page_range %}
34+ {% if page_num == '...' %}
35+ < li > < span class ="pagination-ellipsis "> …</ span > </ li >
36+ {% else %}
3137 < li >
32- {% if page_obj.number == i %}
33- < span class ="pagination-link is-current " aria-current =" page " > {{ i }} </ span >
34- {% else %}
35- < a href =" ?page={{ i }}&search={{ search|urlencode }}&page_size={{ page_obj.paginator.per_page }} "
36- class =" pagination-link " aria-label =" Goto page {{ i }}" > {{ i }} </ a >
37- {% endif %}
38+ < a href =" ?page={{ page_num }}&search={{ search|urlencode }}&page_size={{ current_page_size }} "
39+ class ="pagination-link {% if page_num == page_obj.number %} is-current{% endif %} "
40+ aria-label =" Go to page {{ page_num }} "
41+ {% if page_num == page_obj.number %}aria-current =" page " {% endif %} >
42+ {{ page_num }}
43+ </ a >
3844 </ li >
3945 {% endif %}
40- {% endif %}
41- {% endfor %}
46+ {% endfor %}
47+ </ ul >
48+ </ nav >
49+ {% endif %}
50+ </ div >
4251
43- {% if page_obj.number < page _obj.paginator.num_pages %}
44- {% if page_obj.number < page _obj.paginator.num_pages|add: "-3" %}
45- < li> < span class ="pagination-ellipsis "> …</ span > </ li >
46- {% endif %}
47- < li >
48- < a href ="?page={{ page_obj.paginator.num_pages }}&search={{ search|urlencode }}&page_size={{ page_obj.paginator.per_page }} "
49- class ="pagination-link " aria-label ="Goto page {{ page_obj.paginator.num_pages }} ">
50- {{ page_obj.paginator.num_pages }}
51- </ a >
52- </ li >
53- {% endif %}
54- </ ul >
55- </ nav >
56- {% endif %}
52+ < style >
53+ .select .is-disabled {
54+ opacity : 0.7 ;
55+ cursor : not-allowed;
56+ }
57+ .select .is-disabled select {
58+ cursor : not-allowed;
59+ }
60+ </ style >
61+
62+ < script >
63+ function handlePageSizeChange ( value ) {
64+ const url = new URL ( window . location . href ) ;
65+ const params = new URLSearchParams ( url . search ) ;
66+ params . set ( 'page_size' , value ) ;
67+ params . delete ( 'page' ) ;
68+
69+ const search = params . get ( 'search' ) ;
70+ if ( search ) {
71+ params . set ( 'search' , search ) ;
72+ }
73+
74+ const newUrl = `${ window . location . pathname } ?${ params . toString ( ) } ` ;
75+ window . location . href = newUrl ;
76+ }
77+ </ script >
0 commit comments