displaying "Frequencies of Reported Symptoms" as a table

This commit is contained in:
frankknoll
2023-04-18 11:14:11 +02:00
parent 9f53deb2ee
commit 8eb6f8ff9b
4 changed files with 78 additions and 137 deletions

60
docs/HistogramTable.js Normal file
View File

@@ -0,0 +1,60 @@
class HistogramTable {
#tableElement;
#table;
constructor(tableElement) {
this.#tableElement = tableElement;
}
initialize() {
this.#table = this.#createEmptyTable();
}
display(frequencyBySymptom) {
const symptom_frequency_arrays = Object.entries(frequencyBySymptom);
this.#setTableRows(symptom_frequency_arrays);
}
#createEmptyTable() {
return this.#tableElement.DataTable(
{
language:
{
searchPlaceholder: "Enter Symptom"
},
search:
{
return: false
},
processing: true,
deferRender: true,
order: [[this.#getColumnIndex('Frequency'), "desc"]],
columnDefs:
[
{
searchable: true,
targets: [
this.#getColumnIndex('Symptom')
]
},
]
});
}
#getColumnIndex(columnName) {
switch (columnName) {
case 'Symptom':
return 0;
case 'Frequency':
return 1;
}
}
#setTableRows(rows) {
this.#table
.clear()
.rows.add(rows)
.draw();
}
}