Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual implementation with Mustache #133

Open
benbagley opened this issue Jan 27, 2018 · 1 comment
Open

Visual implementation with Mustache #133

benbagley opened this issue Jan 27, 2018 · 1 comment

Comments

@benbagley
Copy link

benbagley commented Jan 27, 2018

Hi,

I'm currently working on getting this package working and I believe I have it implemented correctly.

I have the following:

route

router.get('/dashboard', ensureAuthenticated, (req, res) => {
  User.paginate({}, { page: 1, limit: 6 }, function(err, result) {
    result.limit - 6
    result.page - 1
  });

  User.find({}, function(err, users) {
    res.render('dashboard/index.hbs', {
      pageTitle: 'Dashboard',
      users: users
    });
  });
});

and I have implemented the package in the user.js and called UserSchema.plugin(mongoosePaginate);.

However I am unsure on how to get a visible implementation of this working so it is clickable through the pages.

I am using Bootstrap 3 and the mustache templating engine.

@shr33narayan
Copy link

shr33narayan commented Feb 19, 2018

I can give you a short idea of what I am using:

In My Route:

router.get('/users', (req, res)=>{
  User.paginate({}, {
    sort: {'_createdAt': -1},
    limit: req.query.l ? parseInt(req.query.l) : 12,
    page: req.query.page ? req.query.page : 1
    })
    .then((result)=>{
      //result is a returned array from the database pagination
      return res.render('admin/dashboard', {
        title: "Dashboard | Admin Panel",
        users: result.docs,
        total: result.total,
        currentPage: result.page,
        limit: result.limit
      });
    })
    .catch((err)=>{
      console.log(err);
      return res.send('Error Contacting the database or Some Trouble happened while exec Pagination Script');
    })
})

In My .pug file (using Bootstrap 4 theme):

         - var PossiblePages = Math.trunc(total/limit)+1;
        - var nextPage = currentPage
        nav(aria-label="...")
          ul.pagination.pagination-md.justify-content-center
            li.page-item(class= {disabled: currentPage==1})
              a.page-link(href="/admin/dashboard?page="+(currentPage-1) tabindex="-1") Previous
            - var p = 1;
            while p <= PossiblePages
              li.page-item(class= {active: currentPage == p} )
                a.page-link(href="/admin/dashboard?page="+p)=p
              - p++;
            li.page-item(class={disabled: currentPage == PossiblePages})
              a.page-link(href="/admin/dashboard?page="+ ++nextPage ) Next

As you can see, I am making use of req.query or ?p=2 (for ex) for getting mine work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants