From adec5deb3553632c405b43091eef106e296dbcca Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 23 Jan 2026 17:33:54 -0600 Subject: DataTables: Improve drawCallback * Use references from the datatables API rather than depending on specific classes existing in the tables. --- uploader/static/js/datatables.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'uploader/static/js') 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); }); } } -- cgit 1.4.1