Pagination.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import Buttons from "./Buttons";
  2. import Label from "./Label";
  3. import Serch from "./Search";
  4. export default class Pagination {
  5. constructor(onPageChange, rowCount, perPage) {
  6. this.currentPage = 1;
  7. this.maxButtons = 10;
  8. this.onPageChange = onPageChange;
  9. this.rowCount = rowCount;
  10. this.perPage = perPage;
  11. this.totalPages = Math.ceil(rowCount / perPage);
  12. }
  13. render() {
  14. this.paginationContainer = document.createElement('div');
  15. this.paginationContainer.classList.add('pagination', 'row');
  16. if(this.totalPages <= 1){
  17. return this.paginationContainer;
  18. }
  19. this.labels = new Label(this.currentPage, this.totalPages, 10, 1000);
  20. this.buttons = new Buttons(this.currentPage, this.totalPages, 10, this.onPageChange, (page) => {
  21. this.labels.updateLabel(page, this.perPage);
  22. this.search.updateSearch(page, this.perPage);
  23. });
  24. this.search = new Serch(this.currentPage, this.totalPages, this.onPageChange, (page, size) => {
  25. this.labels.updateLabel(page, this.perPage);
  26. this.buttons.updateButtons(page, this.perPage);
  27. this.search.updateSearch(page, this.perPage);
  28. });
  29. this.paginationContainer.appendChild(this.labels.render());
  30. this.paginationContainer.appendChild(this.buttons.render());
  31. this.paginationContainer.appendChild(this.search.render());
  32. return this.paginationContainer;
  33. }
  34. changePageSize(onPageChange, rowCount, perPage) {
  35. this.currentPage = 1;
  36. this.maxButtons = 10;
  37. this.onPageChange = onPageChange;
  38. this.rowCount = rowCount;
  39. this.perPage = perPage;
  40. this.totalPages = Math.ceil(rowCount / perPage);
  41. return this.paginationContainer;
  42. }
  43. }