From 0433a9cb880e26c06a8876d18a90c171eee500bd Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 10 Mar 2025 12:31:23 -0500 Subject: Change the way the Row-Selection handler works. --- uploader/static/js/datatables.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'uploader/static') diff --git a/uploader/static/js/datatables.js b/uploader/static/js/datatables.js index 586ef30..76b1877 100644 --- a/uploader/static/js/datatables.js +++ b/uploader/static/js/datatables.js @@ -1,18 +1,25 @@ /** Handlers for events in datatables **/ -$(() => { - $("#tbl-phenotypes-list").on("draw.dt", () => { +var dtAddRowSelectionHandler = (tableId) => { + $(tableId).on("draw.dt", (event) => { $(".chk-row-select").on("change", (event) => { - var checkbox = event.target; - var tablerow = checkbox.parentElement.parentElement; + var checkboxOrRadio = event.target; + var tablerow = checkboxOrRadio.parentElement.parentElement; var tableclass = tablerow.getAttribute("class"); - if(checkbox.checked) { + if(checkboxOrRadio.checked) { + if (checkboxOrRadio.type == "radio") { + $(tableId + " tr").each((index, row) => { + var rowKlass = $(row).attr("class") || ""; + row.setAttribute( + "class", rowKlass.replaceAll("selected", "").trim()); + }); + } tablerow.setAttribute("class", `${tableclass} selected`); } else { tablerow.setAttribute( - "class", tableclass.replace("selected", "").trim()); + "class", tableclass.replaceAll("selected", "").trim()); } }); }); -}); +}; -- cgit v1.2.3