Begin PartsTable class
This commit is contained in:
parent
9839232769
commit
c1d38f4d0c
41
src/table.ts
Normal file
41
src/table.ts
Normal file
@ -0,0 +1,41 @@
|
||||
export class PartsTable {
|
||||
constructor(
|
||||
public htmlTable: HTMLTableElement,
|
||||
public headers: string[],
|
||||
public jsonBOM: part[],
|
||||
) {}
|
||||
|
||||
//Reset table
|
||||
public clearTable(): void {
|
||||
this.htmlTable.innerHTML = '';
|
||||
}
|
||||
|
||||
//Header
|
||||
private createTableHeader(): void {
|
||||
const tHead = this.htmlTable.createTHead();
|
||||
const hRow = tHead.insertRow();
|
||||
//Populate headers with text
|
||||
for (const header of this.headers) {
|
||||
const th = document.createElement('th');
|
||||
const headerText = document.createTextNode(header);
|
||||
th.appendChild(headerText);
|
||||
hRow.appendChild(th);
|
||||
}
|
||||
}
|
||||
|
||||
//Body
|
||||
private createTableBody(): void {
|
||||
this.jsonBOM.map((component) => {
|
||||
//Create a row
|
||||
const tRow = this.htmlTable.insertRow();
|
||||
//Insert part name
|
||||
const partName = tRow.insertCell();
|
||||
const partNameText = document.createTextNode(component.Part);
|
||||
partName.appendChild(partNameText);
|
||||
//Insert part value
|
||||
const partValue = tRow.insertCell();
|
||||
const partValText = document.createTextNode(component.Value);
|
||||
partValue.appendChild(partValText);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user