-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowstudentdetail.js
More file actions
71 lines (58 loc) · 2.9 KB
/
showstudentdetail.js
File metadata and controls
71 lines (58 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
document.addEventListener('DOMContentLoaded', () => {
const searchForm = document.querySelector('.filter-controls form');
const searchRegNoInput = document.getElementById('search_reg_no');
const searchYearSelect = document.getElementById('search_year');
const searchSemesterSelect = document.getElementById('search_semester');
const studentTableBody = document.querySelector('#showstudent tbody');
const clearFilterBtn = document.getElementById('ClearFilterBtn');
// Store all initial rows
const allTableRows = Array.from(studentTableBody.querySelectorAll('tr'));
// Function to display "No data found" message
const showNoDataFound = () => {
studentTableBody.innerHTML = '<tr><td colspan="9" style="text-align: center; color: red;">No data found</td></tr>';
};
// Function to show all rows
const showAllRows = () => {
studentTableBody.innerHTML = ''; // Clear current table body
allTableRows.forEach(row => {
studentTableBody.appendChild(row.cloneNode(true)); // Append a clone to avoid issues with node re-insertion
});
};
// Initially show all rows
showAllRows();
searchForm.addEventListener('submit', (event) => {
event.preventDefault(); // Prevent default form submission
const regNo = searchRegNoInput.value.trim().toLowerCase();
const year = searchYearSelect.value;
const semester = searchSemesterSelect.value;
let foundMatch = false;
const filteredRows = [];
allTableRows.forEach(row => {
const rowRegNo = row.children[4].textContent.trim().toLowerCase(); // Registration Number column
const rowYear = row.children[5].textContent.trim().split('st').join('').split('nd').join('').split('rd').join('').toLowerCase(); // Year column (e.g., "1st" -> "1")
const rowSemester = row.children[6].textContent.trim().split('st').join('').split('nd').join('').split('rd').join('').toLowerCase(); // Semester column (e.g., "1st" -> "1")
const matchesRegNo = regNo === '' || rowRegNo.includes(regNo);
const matchesYear = year === '' || rowYear === year;
const matchesSemester = semester === '' || rowSemester === semester;
if (matchesRegNo && matchesYear && matchesSemester) {
filteredRows.push(row.cloneNode(true)); // Add a clone to the filtered list
foundMatch = true;
}
});
// Clear the current table body
studentTableBody.innerHTML = '';
if (foundMatch) {
filteredRows.forEach(row => {
studentTableBody.appendChild(row);
});
} else {
showNoDataFound();
}
});
clearFilterBtn.addEventListener('click', () => {
searchRegNoInput.value = '';
searchYearSelect.value = '';
searchSemesterSelect.value = '';
showAllRows();
});
});