making Company column searchable

This commit is contained in:
frankknoll
2023-02-02 17:46:20 +01:00
parent d4ac529f5e
commit b58021af04
3 changed files with 211 additions and 71 deletions

File diff suppressed because one or more lines are too long

View File

@@ -48,7 +48,6 @@ class BatchCodeTableInitializer {
this.#getColumnIndex('Deaths'), this.#getColumnIndex('Deaths'),
this.#getColumnIndex('Disabilities'), this.#getColumnIndex('Disabilities'),
this.#getColumnIndex('Life Threatening Illnesses'), this.#getColumnIndex('Life Threatening Illnesses'),
this.#getColumnIndex('Company'),
this.#getColumnIndex('Countries'), this.#getColumnIndex('Countries'),
this.#getColumnIndex('Severe reports'), this.#getColumnIndex('Severe reports'),
this.#getColumnIndex('Lethality') this.#getColumnIndex('Lethality')
@@ -56,7 +55,7 @@ class BatchCodeTableInitializer {
}, },
{ {
orderable: false, orderable: false,
targets: this.#getColumnIndex('Countries') targets: [this.#getColumnIndex('Countries'), this.#getColumnIndex('Company')]
}, },
{ {
render: (data, type, row) => { render: (data, type, row) => {
@@ -105,6 +104,7 @@ class BatchCodeTableInitializer {
}) })
.then(json => { .then(json => {
this.#setTableRows(json.data); this.#setTableRows(json.data);
this.#makeCompanyColumnSearchable();
this.#selectInput(); this.#selectInput();
this.#displayControlColumn(country == 'Global'); this.#displayControlColumn(country == 'Global');
}); });
@@ -122,6 +122,27 @@ class BatchCodeTableInitializer {
.draw(); .draw();
} }
#makeCompanyColumnSearchable() {
// adapted from https://datatables.net/examples/api/multi_filter_select.html
const companyColumn = this.#batchCodeTable.column(this.#getColumnIndex('Company'));
const select = $('<select><option value=""></option></select>')
.appendTo($(companyColumn.header()))
.on('change', function () {
const val = $.fn.dataTable.util.escapeRegex($(this).val());
companyColumn
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
companyColumn
.data()
.unique()
.sort()
.each(function (d, _) {
select.append('<option value="' + d + '">' + d + '</option>');
});
}
#selectInput() { #selectInput() {
const input = document.querySelector(".dataTables_filter input"); const input = document.querySelector(".dataTables_filter input");
input.focus(); input.focus();

View File

@@ -4,7 +4,6 @@ FK-FIXME:
FK-TODO: FK-TODO:
- Histogramme auch speziell für die einzelnen Länder berechnen und anzeigen. - Histogramme auch speziell für die einzelnen Länder berechnen und anzeigen.
- make Company column searchable: https://datatables.net/examples/api/multi_filter_select.html
anacron job: anacron job:
sudo cp src/intensivstationen_howbadismybatch.sh /etc/cron.daily/intensivstationen_howbadismybatch sudo cp src/intensivstationen_howbadismybatch.sh /etc/cron.daily/intensivstationen_howbadismybatch