Files
2026-03-20 12:07:50 +10:00

37 lines
983 B
JavaScript

// создание таблицы
const showTable = (idTable, data) => {
const table = d3.select("#" + idTable);
// создание строк таблицы (столько, сколько элементов в массиве)
const rows = table
.selectAll("tr")
.data(data)
.enter()
.append('tr')
.style("display", "");
// создание ячеек каждой строки на основе каждого элемента массива
const cells = rows
.selectAll("td")
.data(d => Object.values(d))
.enter()
.append("td")
.text(d => d);
// создание шапки таблицы
const head = table
.insert("tr", "tr")
.selectAll("th")
.data(d => Object.keys(data[0]))
.enter()
.append("th")
.text(d => d);
}
const clearTable = (idTable) => {
const table = document.getElementById(idTable);
while (table.children.length > 0) {
table.removeChild(table.children[0]);
}
}