-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1101 from Praju2002/added-reviews-pagination
Added reviews pagination
- Loading branch information
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "ice-cream-parlour-website", | ||
"version": "1.0.0", | ||
"description": "![Ice Cream Website Screenshot](/images/readme.png)", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const reviewsPerPage = 2; // Number of reviews per page | ||
const reviewsContainer = document.getElementById('reviewsContainer'); | ||
const paginationContainer = document.getElementById('pagination'); | ||
const reviews = Array.from(document.querySelectorAll('.review-box')); | ||
|
||
function displayReviews(page) { | ||
// Hide all reviews first | ||
reviews.forEach(review => review.style.display = 'none'); | ||
|
||
// Calculate the start and end index of the reviews for the current page | ||
const start = (page - 1) * reviewsPerPage; | ||
const end = start + reviewsPerPage; | ||
|
||
// Show the reviews for the current page | ||
reviews.slice(start, end).forEach(review => review.style.display = 'block'); | ||
|
||
// Update the pagination buttons | ||
updatePaginationButtons(page); | ||
} | ||
|
||
function updatePaginationButtons(currentPage) { | ||
// Calculate the total number of pages | ||
const totalPages = Math.ceil(reviews.length / reviewsPerPage); | ||
|
||
// Clear the pagination container | ||
paginationContainer.innerHTML = ''; | ||
|
||
// Generate pagination buttons | ||
for (let i = 1; i <= totalPages; i++) { | ||
const button = document.createElement('button'); | ||
button.innerText = i; | ||
button.classList.toggle('active', i === currentPage); | ||
button.addEventListener('click', () => displayReviews(i)); | ||
paginationContainer.appendChild(button); | ||
} | ||
} | ||
|
||
// Initial display of the first page | ||
displayReviews(1); |