Nodejs Pagination
Ejs file[Html page] :
Node js mongodb pagination
<% if (pageCount > 1) { %><ul class="pagination"><% if (currentPage > 1) { %><li><a href="/userdetails?page=1">«</a></li><% } %><% var i = 1;if (currentPage > 5) {i = +currentPage - 4;} %><% if (i !== 1) { %><li class="disabled"><a href="#">...</a></li><% } %><% for (var j = i; j<=pageCount; j++) { %><% if (currentPage == j) { %><li class="active"><span><%= j %> <span class="sr-only">(current)</span></span></li><% } else { %><li><a href="/userdetails?page=<%= j %>"><%= j %></a></li><% } %><% if (j == (+currentPage + 4)) { %><li class="disabled"><a href="#">...</a></li><% break; } %><% } %><% if (currentPage != pageCount) { %><li><a href="/userdetails?page=<%= pageCount %>">»</a></li><% } %></ul> <% } %>
Routes.js
:
var totalRec = 0,pageSize = 5,pageCount = 0;var currentPage = 1;app.get('/userdetails', function (req, res) {Register.find({}).exec(function(err, Register) {if (err) throw err;totalRec = Register.length;pageCount = Math.ceil(totalRec / pageSize);if (typeof req.query.page !== 'undefined') {currentPage = req.query.page;}var start = 0;if(currentPage >1){start = (currentPage - 1) * pageSize;}var data = [];for(var i=start;i<start+pageSize;i++) {if(i < totalRec){data.push(Register[i]);} else {break;}}res.render('userdetails.ejs', { "Register": Register, data:data, pageSize: pageSize, pageCount: pageCount,currentPage: currentPage});});});
10 comments
commentsThanks for sharing the information for more details Mean stack training in hyderabad
ReplyHi I am so glad to be part of this great blog. Keep sharing such quality content. Thank you.
ReplyMEAN Stack Training
MEAN Stack Online Training
Thanks for your support
ReplyNice Post,keep on sharing. Check it once through.
ReplyFull Stack online Training
Full Stack Training
Full Stack Developer Online Training
Full Stack Training in Hyderabad
Full Stack Training in Ameerpet
Full Stack Training Institute
Thanks for sharing the valuable information..... Nice blog
ReplyMeanstack Online Training
Meanstack Training in Hyderabad
Meanstack Training in Ameerpet
Best Meanstack Training in Hyderabad
Nice post keep on sharing.
ReplyMean stack online training
Mean stack training in hyderabad
This post gives good quality information and unique content.
ReplyMean stack online training
Mean stack training in hyderabad
Good post and informative. Thank you very much for sharing this good article, it was so good to read and useful to improve my knowledge as updated, keep blogging. Really the post is very unique.every concepts are captured nice.
Replyoracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
oracle online training
hadoop training in chennai
hadoop training in bangalore
instagram takipçi satın al
Replyinstagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al