@@ -43,8 +43,9 @@ <h1>Flask REST API CRUD</h1>
43
43
44
44
</ tbody >
45
45
</ table >
46
+
46
47
< div id ="pagination ">
47
-
48
+ < button class =" paginate-btn " id =" previous " > Previous </ button >
48
49
</ div >
49
50
</ td >
50
51
</ tr >
@@ -87,7 +88,7 @@ <h2>Edit Form</h2>
87
88
// load data---------------------------------------------
88
89
function loaddata ( page ) {
89
90
if ( page == undefined ) {
90
- page = 1
91
+ page = 1
91
92
}
92
93
$ ( "#load-table" ) . html ( '' ) ;
93
94
$ . ajax ( {
@@ -108,13 +109,24 @@ <h2>Edit Form</h2>
108
109
'</tr>' ) ;
109
110
} ) ;
110
111
$ ( "#pagination" ) . html ( '' ) ;
112
+ if ( data . page_num == 1 ) {
113
+ $ ( "#pagination" ) . append ( '<button class="paginate-btn disable-link" id="previous">Previous</button>' ) ;
114
+ } else {
115
+ $ ( "#pagination" ) . append ( '<button class="paginate-btn" id="previous">Previous</button>' ) ;
116
+ }
117
+
111
118
for ( let i = 1 ; i <= data . total_pages ; i ++ ) {
112
119
if ( i == data . page_num ) {
113
120
$ ( "#pagination" ) . append ( "<a class='active' id=" + i + " href=''>" + i + "</a>" ) ;
114
121
} else {
115
122
$ ( "#pagination" ) . append ( "<a class='' id=" + i + " href=''>" + i + "</a>" ) ;
116
123
}
117
124
}
125
+ if ( data . page_num == data . total_pages ) {
126
+ $ ( "#pagination" ) . append ( '<button class="paginate-btn disable-link" id="next">Next</button>' ) ;
127
+ } else {
128
+ $ ( "#pagination" ) . append ( '<button class="paginate-btn" id="next">Next</button>' ) ;
129
+ }
118
130
}
119
131
} ) ;
120
132
}
@@ -128,6 +140,21 @@ <h2>Edit Form</h2>
128
140
loaddata ( page_id ) ;
129
141
} )
130
142
143
+ $ ( document ) . on ( "click" , "#previous" , function ( e ) {
144
+ e . preventDefault ( ) ;
145
+ var page_id = Number ( $ ( ".active" ) . attr ( "id" ) ) - 1 ;
146
+
147
+ loaddata ( page_id ) ;
148
+ } )
149
+
150
+ $ ( document ) . on ( "click" , "#next" , function ( e ) {
151
+ e . preventDefault ( ) ;
152
+ var page_id = Number ( $ ( ".active" ) . attr ( "id" ) ) + 1 ;
153
+
154
+ loaddata ( page_id ) ;
155
+ } )
156
+
157
+ // show message-------------------------------------------
131
158
function message ( msg , status ) {
132
159
if ( status == true ) {
133
160
$ ( '#error-message' ) . hide ( ) ;
0 commit comments