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

How to apply the pagination #18

Closed
vrrb opened this issue Dec 21, 2020 · 4 comments
Closed

How to apply the pagination #18

vrrb opened this issue Dec 21, 2020 · 4 comments

Comments

@vrrb
Copy link

vrrb commented Dec 21, 2020

I'm not sure how to implement this on my app. Let's say I have an array of items called Items how would I implement this plugin to work on my Items array?

@sant123
Copy link
Owner

sant123 commented Dec 21, 2020

Did you see the Demo in Plunkr? Take a look at script.js.

@vrrb
Copy link
Author

vrrb commented Dec 21, 2020

I did, but I can't see anywhere any v-for to iterate through my items or how to apply pagination to my existing array.

@sant123
Copy link
Owner

sant123 commented Dec 21, 2020

Well, that implementation needs to be done by your side. This is just a plugin that shows a pagination banner below your data. However you can follow this script that may help you in what you need:

export function paginateItems(items, currentPage, itemsPerPage) {
  const start = currentPage * itemsPerPage - itemsPerPage;
  const end = currentPage * itemsPerPage;

  return items.slice(start, end);
}

const data = [
    1,2,3,
    4,5,6,
    7,8,9,
];

// Suppose you are going to show 2 items per page and you are in the 3rd page.

const pageData = paginateItems(data, 3, 2);

console.log(pageData); // [ 5, 6 ]

That pageData will be in your v-for directive. Hope it helps.

@vrrb
Copy link
Author

vrrb commented Dec 21, 2020

It helps. thanks!

@vrrb vrrb closed this as completed Dec 21, 2020
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