-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript4.js
More file actions
70 lines (59 loc) · 2.4 KB
/
script4.js
File metadata and controls
70 lines (59 loc) · 2.4 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
$(document).ready(() => {
// Function to fetch data from the server
function fetchDataFromServer() {
// Use AJAX to fetch data from your server
$.ajax({
url: '/', // Replace with your actual endpoint
method: 'GET',
dataType: 'json',
success: function (data) {
// Call a function to create the table based on the retrieved data
createTableFromData(data);
},
error: function (error) {
console.error('Error fetching data:', error);
}
});
}
// Function to create the table based on the retrieved data
function createTableFromData(data) {
const tableBody = $("#copo tbody");
// Loop through the data and create rows for each entry
data.forEach(entry => {
const newRow = $("<tr>");
// Loop through the properties of each entry and create cells
for (const key in entry) {
if (entry.hasOwnProperty(key)) {
const cell = $("<td>").text(entry[key]);
newRow.append(cell);
}
}
// Append the new row to the table body
tableBody.append(newRow);
});
}
// Fetch data and create the table when the page loads
fetchDataFromServer();
const sidebar = document.querySelector(".sidebar");
const submenuItems = document.querySelectorAll(".submenu_item");
const sidebarOpen = document.querySelector("#sidebarOpen");
const sidebarClose = document.querySelector(".collapse_sidebar");
const sidebarExpand = document.querySelector(".expand_sidebar");
sidebarOpen.addEventListener("click", () => sidebar.classList.toggle("close"));
sidebarClose.addEventListener("click", () => {
sidebar.classList.add("close", "hoverable");
});
sidebarExpand.addEventListener("click", () => {
sidebar.classList.remove("close", "hoverable");
});
sidebar.addEventListener("mouseenter", () => {
if (sidebar.classList.contains("hoverable")) {
sidebar.classList.remove("close");
}
});
sidebar.addEventListener("mouseleave", () => {
if (sidebar.classList.contains("hoverable")) {
sidebar.classList.add("close");
}
});
});