about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2026-01-23 17:33:54 -0600
committerFrederick Muriuki Muriithi2026-01-23 17:33:54 -0600
commitadec5deb3553632c405b43091eef106e296dbcca (patch)
treee3b3cb8cdb959570fcaac2b5b0d91c792c97abf7
parent24cbc791a152dc60a84eb25455888d10479305f6 (diff)
downloadgn-uploader-adec5deb3553632c405b43091eef106e296dbcca.tar.gz
DataTables: Improve drawCallback
* Use references from the datatables API rather than depending on
  specific classes existing in the tables.
-rw-r--r--uploader/static/js/datatables.js20
1 files changed, 9 insertions, 11 deletions
diff --git a/uploader/static/js/datatables.js b/uploader/static/js/datatables.js
index d88d481..3259987 100644
--- a/uploader/static/js/datatables.js
+++ b/uploader/static/js/datatables.js
@@ -38,17 +38,15 @@ var buildDataTable = (tableId, data = [], columns = [], userSettings = {}) => {
             lengthMenu: "",
             info: ""
         },
-        drawCallback: (settings) => {
-            $(this[0]).find("tbody tr").each((idx, row) => {
-                var arow = $(row);
-                var checkboxOrRadio = arow.find(".chk-row-select");
-                if (checkboxOrRadio) {
-                    if (arow.hasClass("selected")) {
-                        checkboxOrRadio.prop("checked", true);
-                    } else {
-                        checkboxOrRadio.prop("checked", false);
-                    }
-                }
+        drawCallback: function (settings) {
+            var api = this.api();
+            api.rows({selected: true}).nodes().each((node, index) => {
+                $(node).find('input[type="checkbox"]:checked')
+                      .prop("checked", true);
+            });
+            api.rows({selected: false}).nodes().each((node, index) => {
+                $(node).find('input[type="checkbox"]:not(:checked)')
+                    .prop("checked", false);
             });
         }
     }