displaying "Frequencies of Reported Symptoms" as a table
This commit is contained in:
60
docs/HistogramTable.js
Normal file
60
docs/HistogramTable.js
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user