Tuesday, 30 May 2017

nodejs) how to make a pagination like airbnb?

1) 1 2 3 ... 17
2) 1 ... 4 5 6 ... 17
3) 1 ... 15 16 17

i want to make this style pagination in ejs

please help me

this is my router

router.get('/', function(req,res){
var reqPage = req.param('page');
if(reqPage == null) {reqPage = 1};
var pageContentCount = 4;
var skipCount = (reqPage-1)*pageContentCount;
var totalCount;
boardModel.count({},function(err, result){
if(err) res.send(err);
totalCount = Math.ceil(result/pageContentCount);
boardModel.find({}).sort({id:1}).skip(skipCount).limit(pageContentCount).exec(function(err, contents) {
if(err) res.send(err);

          res.render('board/list', {contents:contents,totalCount:totalCount,reqPage:Number(reqPage)});
    });
});

});



via young

No comments:

Post a Comment