previous next paginations

currentPage: Tracks the current page number. questionsPerPage: Sets the number of questions per page (5). currentQuestions: Computes the questions to display based on the current page. Pagination Controls: "Previous" and "Next" buttons allow navigation and are disabled on the first or last page.
 avatar
user_3824920
plain_text
16 days ago
674 B
1
Indexable
Never
  @track questions = [];
  @track currentPage = 1; // Current page
  questionsPerPage = 5; // Number of questions per page

  get currentQuestions() {
    const start = (this.currentPage - 1) * this.questionsPerPage;
    const end = start + this.questionsPerPage;
    return this.questions.slice(start, end);
  }

  get isFirstPage() {
    return this.currentPage === 1;
  }

  get isLastPage() {
    return this.currentPage * this.questionsPerPage >= this.questions.length;
  }

  previousPage() {
    if (this.currentPage > 1) {
      this.currentPage--;
    }
  }

  nextPage() {
    if (!this.isLastPage) {
      this.currentPage++;
    }
  }
Leave a Comment