treehouse/static/js/sandbox/table.js

23 lines
722 B
JavaScript
Raw Normal View History

2024-04-07 18:11:56 +02:00
import { addElement } from "treehouse/sandbox.js";
export function showTable(data, schema) {
let table = document.createElement("table");
let thead = table.appendChild(document.createElement("thead"));
for (let column of schema.columns) {
let th = thead.appendChild(document.createElement("th"));
th.textContent = column;
}
let tbody = table.appendChild(document.createElement("tbody"));
for (let row of data) {
let tr = tbody.appendChild(document.createElement("tr"));
for (let column of schema.columns) {
let td = tr.appendChild(document.createElement("td"));
td.textContent = `${row[column]}`;
}
}
addElement(table);
}