diff options
| author | Frederick Muriuki Muriithi | 2026-01-23 17:33:54 -0600 |
|---|---|---|
| committer | Frederick Muriuki Muriithi | 2026-01-23 17:33:54 -0600 |
| commit | adec5deb3553632c405b43091eef106e296dbcca (patch) | |
| tree | e3b3cb8cdb959570fcaac2b5b0d91c792c97abf7 | |
| parent | 24cbc791a152dc60a84eb25455888d10479305f6 (diff) | |
| download | gn-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.js | 20 |
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); }); } } |
