From 6575e418e78f5d79ed15f85ed14be304d022c207 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Fri, 29 Apr 2022 14:39:56 +0200 Subject: [PATCH] fix undefined This will fix when you select all lots and you make change that clears list --- ereuse_devicehub/static/js/main_inventory.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 13396a46..30c56c03 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -18,7 +18,7 @@ $(document).ready(() => { }) class TableController { - static #tableRows = table.activeRows; + static #tableRows = () => table.activeRows.length > 0 ? table.activeRows : []; static #tableRowsPage = () => table.pages[table.rows().dt.currentPage - 1]; @@ -26,7 +26,8 @@ class TableController { * @returns Selected inputs from device list */ static getSelectedDevices() { - return this.#tableRows + if (this.#tableRows() == undefined) return []; + return this.#tableRows() .filter(element => element.querySelector("input").checked) .map(element => element.querySelector("input")) } @@ -35,6 +36,7 @@ class TableController { * @returns Selected inputs in current page from device list */ static getAllSelectedDevicesInCurrentPage() { + if (this.#tableRowsPage() == undefined) return []; return this.#tableRowsPage() .filter(element => element.querySelector("input").checked) .map(element => element.querySelector("input")) @@ -44,7 +46,8 @@ class TableController { * @returns All inputs from device list */ static getAllDevices() { - return this.#tableRows + if (this.#tableRows() == undefined) return []; + return this.#tableRows() .map(element => element.querySelector("input")) } @@ -52,6 +55,7 @@ class TableController { * @returns All inputs from current page in device list */ static getAllDevicesInCurrentPage() { + if (this.#tableRowsPage() == undefined) return []; return this.#tableRowsPage() .map(element => element.querySelector("input")) }