-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.js
51 lines (42 loc) · 897 Bytes
/
table.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
export class Table {
head = [];
rows = [];
constructor(head) {
this.head = head;
}
_genTh(columnName) {
return `<th>${columnName}</th>`;
}
_genTd(columnName) {
return `<td>${columnName}</td>`;
}
_genTr(row) {
let rowHTML = "<tr>";
row.forEach((cell) => {
const cellHTML = this._genTd(cell);
rowHTML += cellHTML;
});
return rowHTML + "</tr>";
}
_genHead() {
let rowHTML = "<tr>";
this.head.forEach((cell) => {
const cellHTML = this._genTh(cell);
rowHTML += cellHTML;
});
return rowHTML + "</tr>";
}
_genContentHTML() {
let contentHTML = "";
this.rows.forEach((row) => {
contentHTML += this._genTr(row);
});
return contentHTML;
}
genTable() {
return "<table>" + this._genHead() + this._genContentHTML() + "</table>";
}
push(row) {
this.rows.push(row);
}
}