starting VaccineDistributionByZipcode

This commit is contained in:
frankknoll
2023-03-08 21:41:56 +01:00
parent f5a260b0d2
commit c1c5df5d8d
6 changed files with 240 additions and 11 deletions

View File

@@ -0,0 +1,81 @@
class VaccineDistributionByZipcodeTableInitializer {
#tableElement;
#table;
constructor({ tableElement }) {
this.#tableElement = tableElement;
}
initialize() {
this.#table = this.#createEmptyTable();
this.#loadDataIntoTable();
}
#createEmptyTable() {
return this.#tableElement.DataTable(
{
language:
{
searchPlaceholder: "Enter Batch Code"
},
search:
{
return: false
},
processing: true,
deferRender: true,
columnDefs:
[
{
searchable: false,
targets: [this.#getColumnIndex('DOSES_SHIPPED')]
},
{
searchable: true,
targets: [
this.#getColumnIndex('PROVIDER_NAME'),
this.#getColumnIndex('ZIPCODE_SHP'),
this.#getColumnIndex('LOT_NUMBER'),
]
},
]
});
}
#getColumnIndex(columnName) {
switch (columnName) {
case 'PROVIDER_NAME':
return 0;
case 'ZIPCODE_SHP':
return 1;
case 'LOT_NUMBER':
return 2;
case 'DOSES_SHIPPED':
return 3;
}
}
#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();
input.select();
}
}