-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
75 lines (67 loc) · 2.08 KB
/
init.js
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
72
73
74
75
// 1. dynamically append 2600 cells
let cellgrid = document.querySelector(".cell-content");
let cells = "";
cells += `<div class="top-right-cell"></div>`
cells += `<div class="top-row">`
for (let i = 0; i < 26; i++) {
cells += `<div class="top-row-cell">${String.fromCharCode(65 + i)}</div>`
}
cells += `</div>`;
cells += `<div class="left-col">`
for (let i = 0; i < 100; i++) {
cells += `<div class="left-col-cell">${i + 1}</div>`
}
cells += `</div>`;
cells += `<div class="cells">`
for (let i = 0; i < 100; i++) {
cells += `<div class="row">`;
for (let j = 0; j < 26; j++) {
cells += `<div class="cell" rowid="${i}" colid="${j}" contenteditable="true"></div>`;
}
cells += `</div>`;
}
cells += `</div>`;
// convert string to html
cellgrid.innerHTML = cells;
// 2. Initialise a local database
let sheetdb=[];
let db;
function initdb(){
let newdb=[];
for (let i = 0; i < 100; i++) {
let row = [];
for (let j = 0; j < 26; j++) {
// name = A1 => i decides no and j decides alphabet
let rowno=i+1;
let colno=String.fromCharCode(65+j);
let a=colno+rowno;
let object = {
"name":a,
"value":"",
"formula":"",
"dependencies":[],
"parents":[]
}
row.push(object);
}
newdb.push(row);
}
db=newdb;
sheetdb.push(newdb);
}
initdb();
function initUI(arr){
for(let i=0;i<allcells.length;i++){
allcells[i].textContent="";
}
}
// function loadUI(arr){for(let i=0;i<100;i++){for(let j=0;j<26;j++){document.querySelector(`div[rowid="${i}"][colid="${j}"]`).textContent=arr[i][j].value;}}}
function loadUI(arr){
for(let i=0;i<allcells.length;i++){
// bring rowid and colid from ith cell
let rowz = allcells[i].getAttribute("rowid");
let colz= allcells[i].getAttribute("colid");
// set textcontent
allcells[i].textContent=db[rowz][colz].value;
}
}