From ec8838719bf004cae83b69cd2c54e6f73e42edcc Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 7 Mar 2021 21:37:26 +0100 Subject: [PATCH] improve table sorting --- UI/Component/Table.js | 33 +++++++++++++++++++++++++++++++++ UI/GeneralUI.js | 13 +++++++++++++ Views/TableView.js | 14 ++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/UI/Component/Table.js b/UI/Component/Table.js index 0943cd0..ee9f02b 100644 --- a/UI/Component/Table.js +++ b/UI/Component/Table.js @@ -145,6 +145,12 @@ export class Table for (let i = 0; i < length; ++i) { this.bindFiltering(filters[i], id); } + + const checkboxes = this.tables[id].getCheckboxes(); + length = checkboxes.length; + for (let i = 0; i < length; ++i) { + this.bindCheckbox(checkboxes[i], id); + } }; /** @@ -235,6 +241,7 @@ export class Table const columnName = this.closest('td').getAttribute('data-name'); + // only necessary for retrieving remote data table.setAttribute('data-sorting', (sortType > 0 ? '+' : '-') + (columnName !== null ? columnName : cellId)); if (table.getAttribute('data-src') !== null) { @@ -350,6 +357,32 @@ export class Table }); }; + /** + * Checkbox select. + * + * @param {Element} checkbox Filter button + * @param {Object} id Table id + * + * @return {void} + * + * @since 1.0.0 + */ + bindCheckbox(checkbox, id) + { + checkbox.addEventListener('click', function (event) + { + const columnId = checkbox.closest('td').cellIndex; + const rows = checkbox.closest('table').querySelectorAll('tbody tr'); + const rowLength = rows.length; + const status = checkbox.checked; + + for (let i = 0; i < rowLength; ++i) { + const box = rows[i].cells[columnId].querySelector('input[type=checkbox]'); + box.checked = status; + } + }); + } + static getRemoteData (table) { const data = { diff --git a/UI/GeneralUI.js b/UI/GeneralUI.js index 23ac707..5547c94 100644 --- a/UI/GeneralUI.js +++ b/UI/GeneralUI.js @@ -68,6 +68,19 @@ export class GeneralUI // @todo: implement middle mouse click e[i].addEventListener('click', function(event) { + if ((event.target.parentElement !== this + && event.target.parentElement.getElementsByTagName('input').length > 0) + || (event.target.getElementsByTagName('input').length > 0) + ) { + const input = event.target.querySelector('input'); + + if (input !== null) { + input.click(); + } + + return; + } + jsOMS.preventAll(event); history.pushState(null, null, window.location); diff --git a/Views/TableView.js b/Views/TableView.js index 6bf3584..52227a2 100644 --- a/Views/TableView.js +++ b/Views/TableView.js @@ -134,6 +134,20 @@ export class TableView ); }; + /** + * Get table header elements which provide filter functionality + * + * @return {Array} + * + * @since 1.0.0 + */ + getCheckboxes() + { + return document.querySelectorAll( + '#' + this.id + ' thead input[type=checkbox]' + ); + }; + /** * Get row elements which allow to swap the current row with another row *