Add search functionality to admin and student pages

This commit is contained in:
Alvin
2025-10-29 10:01:42 +01:00
parent 880aa93649
commit 50368cc256
8 changed files with 167 additions and 7 deletions

View File

@@ -62,11 +62,15 @@ async function loadReservations() {
function filterAndDisplayReservations() {
const locationFilter = document.getElementById('locationFilter').value;
const statusFilter = document.getElementById('statusFilter').value;
const searchTerm = document.getElementById('searchInput').value.toLowerCase();
const filteredReservations = reservations.filter(reservation => {
const locationMatch = locationFilter === 'all' || reservation.location === locationFilter;
const statusMatch = statusFilter === 'all' || reservation.status === statusFilter;
return locationMatch && statusMatch;
const searchMatch = searchTerm === '' ||
reservation.itemName.toLowerCase().includes(searchTerm) ||
reservation.location.toLowerCase().includes(searchTerm);
return locationMatch && statusMatch && searchMatch;
});
const reservationsList = document.getElementById('reservationsList');
@@ -171,6 +175,23 @@ function setupEventListeners() {
localStorage.clear();
window.location.href = '/index.html';
});
// Search functionality
const searchInput = document.getElementById('searchInput');
const clearSearch = document.getElementById('clearSearch');
searchInput.addEventListener('input', filterAndDisplayReservations);
searchInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
filterAndDisplayReservations();
}
});
clearSearch.addEventListener('click', () => {
searchInput.value = '';
filterAndDisplayReservations();
searchInput.focus();
});
}
// Auto refresh functionality