git.schokokeks.org
Repositories
Help
Report an Issue
fs-draft.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
18080c6
Branches
Tags
master
midgard
vorlage
fs-draft.git
source
logic
client
table.js
foo
fenris
commited
18080c6
at 2016-04-24 18:00:07
table.js
Blame
History
Raw
"use strict"; class class_format { constructor(title, extract, format = function (x) {return x;}) { this.title = title; this.extract = extract; this.format = tormat; } } class class_table { constructor(columns, rows = []) { this.columns = columns; this.rows = rows; } add(row) { this.rows.push(row); } fill(rows) { rows.forEach(row => this.add(row)); } generate() { let dom_table = document.createElement("table"); { let dom_thead = document.createElement("thead"); [null].forEach ( function (dummy) { let dom_row = document.createElement("tr"); this.columns.forEach ( function (column) { let dom_cell = document.createElement("th"); dom_cell.textContent = column.title; dom_row.appendChild(dom_cell); } ); dom_thead.appendChild(dom_row); } ); dom_table.appendChild(dom_thead); } { let dom_thead = document.createElement("tbody"); this.rows.forEach ( function (row) { let dom_row = document.createElement("tr"); this.columns.forEach ( function (column) { let dom_cell = document.createElement("td"); dom_cell.textContent = column.format(column.extract(row)); dom_row.appendChild(dom_cell); } ); dom_thead.appendChild(dom_row); } ); dom_table.appendChild(dom_tbody); } return dom_table; } }