feature: data now show in the table

This commit is contained in:
Jan Klattenhoff 2024-01-19 09:12:17 +01:00
parent cdd547247b
commit b16307c2d2

@ -2,15 +2,30 @@
{% block javascripts %}
<script>
function addPrinterToTable(printer) {
function addTableData(tableRow, data) {
const tableData = document.createElement('td');
tableData.textContent = data;
tableRow.appendChild(tableData);
}
function addPrinterToTable(tableBody, printer) {
const tableRow = document.createElement('tr');
addTableData(tableRow, printer.name);
addTableData(tableRow, printer.price.toFixed(2) + '$');
addTableData(tableRow, printer.build_volume);
addTableData(tableRow, printer.max_speed);
tableBody.appendChild(tableRow);
}
function reloadTable() {
fetch('/printer', {method: 'GET'}).then(response => {
response.json().then(json => {
for (printer of json) {
addPrinterToTable(printer);
const tableBody = document.getElementById('table-body');
tableBody.innerHTML = null;
addPrinterToTable(tableBody, printer);
}
});
});