refactoring

This commit is contained in:
frankknoll
2023-03-08 22:15:30 +01:00
parent c1c5df5d8d
commit 2f33a3d618

View File

@@ -1,19 +1,18 @@
class VaccineDistributionByZipcodeTableInitializer {
#tableElement;
#table;
constructor({ tableElement }) {
this.#tableElement = tableElement;
}
initialize() {
this.#table = this.#createEmptyTable();
this.#loadDataIntoTable();
this.#createTable();
this.#selectInput();
}
#createEmptyTable() {
return this.#tableElement.DataTable(
#createTable() {
this.#tableElement.DataTable(
{
language:
{
@@ -23,6 +22,7 @@ class VaccineDistributionByZipcodeTableInitializer {
{
return: false
},
ajax: 'data/vaccineDistributionByZipcode/VaccineDistributionByZipcode.json',
processing: true,
deferRender: true,
columnDefs:
@@ -56,23 +56,6 @@ class VaccineDistributionByZipcodeTableInitializer {
}
}
#loadDataIntoTable() {
// FK-TODO: show "Loading.." message or spinning wheel.
fetch('data/vaccineDistributionByZipcode/VaccineDistributionByZipcode.json')
.then(response => response.json())
.then(json => {
this.#setTableRows(json.data);
this.#selectInput();
});
}
#setTableRows(rows) {
this.#table
.clear()
.rows.add(rows)
.draw();
}
#selectInput() {
const input = document.querySelector(".dataTables_filter input");
input.focus();