From 2f33a3d6185df3bd4924e301e330442c3effb6a8 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Wed, 8 Mar 2023 22:15:30 +0100 Subject: [PATCH] refactoring --- ...neDistributionByZipcodeTableInitializer.js | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/docs/VaccineDistributionByZipcodeTableInitializer.js b/docs/VaccineDistributionByZipcodeTableInitializer.js index a2f5a1c1307..335dbafdc88 100644 --- a/docs/VaccineDistributionByZipcodeTableInitializer.js +++ b/docs/VaccineDistributionByZipcodeTableInitializer.js @@ -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();