Skip to content
New issue

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

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

Already on GitHub? # to your account

Code for Prev and Next buttons #771

Open
carlos-widgilabs opened this issue Dec 6, 2023 · 0 comments
Open

Code for Prev and Next buttons #771

carlos-widgilabs opened this issue Dec 6, 2023 · 0 comments

Comments

@carlos-widgilabs
Copy link

carlos-widgilabs commented Dec 6, 2023

`

import List from "list.js";

document.addEventListener("DOMContentLoaded", function () {
  
  let itemsPerPage = 60;
  let items = itemsPerPage; // using for calculate paginate

  /* init list js */
  const listJS = new List('item-list--container', {
    valueNames: ['item'],
    page: itemsPerPage,
    pagination: true,
    searchClass: 'search-input'
  });

  /* function prev button */
  document.getElementById('prev-btn').addEventListener('click', function(event) {
    event.preventDefault();

    // get current page/list item active
    const activeItem = document.querySelector('ul.pagination li.active');

    // verify if exists prev page
    if (activeItem.previousElementSibling !== null) {

      // calculate prev page using total pages
      listJS.show( listJS.i - listJS.page, itemsPerPage);
    }
  });

  // function prev button
  document.getElementById('next-btn').addEventListener('click', function(event) {
    event.preventDefault();

    // get current page/list item active
    const activeItem = document.querySelector('ul.pagination li.active');

    // verify if exists next page
    if (activeItem.nextElementSibling !== null) {

      // calculate next page using total items.
      listJS.show(listJS.i + items, itemsPerPage);
    }
  });
});
`
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant