2424 id ="example2_paginate ">
2525 < ul class ="pagination ">
2626 {% if pagination_required %}
27- < li class ="paginate_button previous disabled "
28- id ="example2_previous ">
29- < a href ="# " aria-controls ="example2 " data-dt-idx ="0 "
30- tabindex ="0 "> {% trans 'Previous' %}</ a > </ li >
31- {% for i in page_range %}
32- {% adminlte_paginator_number cl i %}
33- {% endfor %}
34- < li class ="paginate_button next disabled " id ="example2_next ">
35- < a href ="# "
36- aria-controls ="example2 "
37- data-dt-idx ="7 "
38- tabindex ="0 "> {% trans 'Next' %}</ a >
39- </ li >
27+ < li class ="paginate_button previous disabled "
28+ id ="example2_previous ">
29+ < a href ="# " aria-controls ="example2 " data-dt-idx ="0 "
30+ tabindex ="0 "> {% trans 'Previous' %}</ a > </ li >
31+ {% for i in page_range %}
32+ {% adminlte_paginator_number cl i %}
33+ {% endfor %}
34+ < li class ="paginate_button next disabled " id ="example2_next ">
35+ < a href ="# "
36+ aria-controls ="example2 "
37+ data-dt-idx ="7 "
38+ tabindex ="0 "> {% trans 'Next' %}</ a >
39+ </ li >
40+ < script type ="text/javascript ">
41+ let pageRange = [ ]
42+ { % for p in page_range % }
43+ pageRange . push ( '{{ p }}' )
44+ { % endfor % }
45+ // console.log(pageRange)
46+ let currentPage = document . querySelector ( "#example2_paginate > ul > li.active > a" ) . innerText
47+ let previous = document . querySelector ( "#example2_previous > a" )
48+ let next = document . querySelector ( "#example2_next > a" )
49+ let target_href = window . location . search . replace ( / \? p = \d + / g, '' ) . replace ( / & p = \d + / g, '' )
50+ // previous button
51+ if ( ( Number ( pageRange [ 0 ] ) + 1 ) . toString ( ) !== currentPage ) {
52+ previous . parentElement . setAttribute ( 'class' , 'paginate_button previous' )
53+ previous . setAttribute ( 'href' , target_href ? target_href + `&p=${ Number ( currentPage ) - 2 } ` : target_href + `?p=${ Number ( currentPage ) - 2 } ` )
54+ } else {
55+ previous . parentElement . setAttribute ( 'class' , 'paginate_button previous disabled' )
56+ previous . setAttribute ( 'href' , 'javascript:void(0);' )
57+ }
58+ // next button
59+ if ( ( Number ( pageRange [ pageRange . length - 1 ] ) + 1 ) . toString ( ) !== currentPage ) {
60+ next . parentElement . setAttribute ( 'class' , 'paginate_button next' )
61+ next . setAttribute ( 'href' , target_href ? target_href + `&p=${ currentPage } ` : target_href + `?p=${ currentPage } ` )
62+ } else {
63+ next . parentElement . setAttribute ( 'class' , 'paginate_button next disabled' )
64+ next . setAttribute ( 'href' , 'javascript:void(0);' )
65+ }
66+ </ script >
4067 {% endif %}
4168 </ ul >
4269 </ div >
4370 </ div >
44- </ div >
71+ </ div >
0 commit comments