Skip to content

Commit f2a568e

Browse files
committed
Previous and next button
1 parent 1570ccf commit f2a568e

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

static/css/style.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,19 @@ h1{
192192
}
193193
#pagination a.active{
194194
background: #27ae60;
195+
pointer-events: none;
196+
197+
}
198+
.paginate-btn{
199+
background: #2980b9;
200+
color: white;
201+
border: 0;
202+
padding: 8px 10px;
203+
margin-right: 5px;
204+
border-radius: 3px;
205+
cursor: pointer;
206+
}
207+
.disable-link{
208+
background: #27ae60;
209+
pointer-events: none;
195210
}

templates/index.html

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ <h1>Flask REST API CRUD</h1>
4343

4444
</tbody>
4545
</table>
46+
4647
<div id="pagination">
47-
48+
<button class="paginate-btn" id="previous">Previous</button>
4849
</div>
4950
</td>
5051
</tr>
@@ -87,7 +88,7 @@ <h2>Edit Form</h2>
8788
// load data---------------------------------------------
8889
function loaddata(page){
8990
if (page == undefined){
90-
page =1
91+
page = 1
9192
}
9293
$("#load-table").html('');
9394
$.ajax({
@@ -108,13 +109,24 @@ <h2>Edit Form</h2>
108109
'</tr>');
109110
});
110111
$("#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+
111118
for (let i = 1; i <= data.total_pages; i++) {
112119
if (i == data.page_num){
113120
$("#pagination").append("<a class='active' id="+i+" href=''>"+i+"</a>");
114121
}else{
115122
$("#pagination").append("<a class='' id="+i+" href=''>"+i+"</a>");
116123
}
117124
}
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+
}
118130
}
119131
});
120132
}
@@ -128,6 +140,21 @@ <h2>Edit Form</h2>
128140
loaddata(page_id);
129141
})
130142

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-------------------------------------------
131158
function message(msg, status) {
132159
if (status == true){
133160
$('#error-message').hide();

0 commit comments

Comments
 (0)