-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (52 loc) · 2.18 KB
/
Copy pathscript.js
File metadata and controls
64 lines (52 loc) · 2.18 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
let data = {
expressions: [
],
}
async function working(){
const response = await fetch("https://opensheet.elk.sh/1ubqWJzUzfBdwrCENswCGvfH6mhaPYfh_mCNAeZcUb_E/page");
const resdata = await response.json();
data.expressions=resdata;
let columns = Object.keys(data.expressions[0]); // Define an array of data.expressions objects keys for table columns
shuffleArray(data.expressions);
// Create the table
let container = document.querySelector(".container");
let table = document.createElement("table");
table.classList = "table table-striped table-bordered";
// create table header elemetns
let thead = document.createElement("thead");
let tr = document.createElement("tr");
// make table columns
columns.map(key => {
let th = document.createElement("th");
th.setAttribute("scope", "col");
th.innerHTML = key;
tr.appendChild(th)
});
thead.appendChild(tr);
table.appendChild(thead);
let tbody = document.createElement("tbody"); //create table body
table.appendChild(tbody); //append table body to its table
// add data to table
data.expressions.map(item=>{
let tr = document.createElement("tr"); // tr data rows
let values = Object.values(item); // an array for each row values
values.map(value=> {
let td = document.createElement("td"); // make cells
td.innerHTML = value; //assign values to cells
tr.appendChild(td); //append cells into rows
});
tbody.appendChild(tr); //append data rows into table body
})
container.appendChild(table); //append table into page container
const fase = document.querySelectorAll(".container > table > tbody > tr");
fase.forEach(el => el.addEventListener('click', event => {
event.target.closest("tr").querySelectorAll("td")[1].classList.toggle("fontsizeIn")
}))
}
document.addEventListener("DOMContentLoaded", working())
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}