Clear table when uploading new bom

This commit is contained in:
Nick Playfair 2021-02-22 22:53:17 +00:00
parent eba25d02b1
commit 56840067f5
3 changed files with 14 additions and 7 deletions

View File

@ -11,6 +11,10 @@ function isJunk(element) {
return !rejectedParts.includes(element.Part); return !rejectedParts.includes(element.Part);
} }
function clearTable() {
document.querySelector('table').innerHTML = '';
}
function generateTableHead(table, data) { function generateTableHead(table, data) {
const thead = table.createTHead(); const thead = table.createTHead();
const row = thead.insertRow(); const row = thead.insertRow();
@ -38,8 +42,7 @@ function generateTableBody(table, data) {
function displayMarkup() { function displayMarkup() {
const tableCode = document.querySelector('table').outerHTML; const tableCode = document.querySelector('table').outerHTML;
const markup = document.getElementById('markup'); const markup = document.getElementById('markup');
const beautifulCode = pretty(tableCode); markup.innerText = pretty(tableCode);
markup.innerText = beautifulCode;
} }
function makeTable(csvString) { function makeTable(csvString) {
@ -62,10 +65,14 @@ function makeTable(csvString) {
} }
function handleFiles() { function handleFiles() {
const csvFilePath = this.files[0]; const csvFilePath = this.files[0];
const reader = new FileReader(); const reader = new FileReader();
reader.readAsText(csvFilePath); reader.readAsText(csvFilePath);
reader.onload = () => makeTable(reader.result); reader.onload = () => {
clearTable();
makeTable(reader.result);
};
} }
const csvPicker = document.getElementById('csvFile'); const csvPicker = document.getElementById('csvFile');

View File

@ -20,7 +20,7 @@
<section> <section>
<h2>Table HTML</h2> <h2>Table HTML</h2>
<!-- <textarea id="markup" cols="30" rows="10"></textarea> --> <!-- <textarea id="markup" cols="30" rows="10"></textarea> -->
<pre><code id="markup" class="language-html"></code></pre> <pre contenteditable=""><code id="markup" class="language-html"></code></pre>
</section> </section>
</main> </main>

View File

@ -1,7 +1,7 @@
header { header {
margin: 1.5rem; margin: 1.5rem;
} }
header h1 { header h1, h2 {
text-align: center; text-align: center;
} }
main { main {
@ -10,9 +10,9 @@ main {
flex-flow: wrap; flex-flow: wrap;
min-width: 500px; min-width: 500px;
max-width: 80vw; max-width: 80vw;
justify-content: space-evenly; justify-content: space-between;
} }
section { section {
flex 0 0 50%; flex: 0 0 45%;
} }