From c28aaf46656d47240c301fa1c63c78b63d8e3379 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sat, 9 Aug 2025 23:17:53 +0100 Subject: [PATCH] Improve band statistics update logic Ensures statistics are updated both on DataTable initialization and after rendering. Adds a fallback selector for counting active bands and delays initial statistics update to wait for table rendering. --- assets/js/sections/bands.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/assets/js/sections/bands.js b/assets/js/sections/bands.js index c7bda37d..69ff615c 100644 --- a/assets/js/sections/bands.js +++ b/assets/js/sections/bands.js @@ -83,6 +83,10 @@ $('.bandtable').DataTable({ ], "drawCallback": function() { updateStatistics(); + }, + "initComplete": function() { + // Ensure statistics are updated when table is fully initialized + updateStatistics(); } }); @@ -138,6 +142,13 @@ $('#showAll').addClass('active'); // Update statistics function updateStatistics() { var activeBands = $('.band-checkbox-cell input[type="checkbox"]:checked').length; + + // Fallback: if the class-based selector doesn't work, try alternative selectors + if (activeBands === 0) { + // Try finding by column position (first column checkboxes) + activeBands = $('.bandtable tbody tr td:first-child input[type="checkbox"]:checked').length; + } + $('#activeBandsCount').text(activeBands); // Update visible rows count @@ -148,7 +159,10 @@ function updateStatistics() { // Update statistics on page load $(document).ready(function() { - updateStatistics(); + // Wait for table to be fully rendered before calculating stats + setTimeout(function() { + updateStatistics(); + }, 500); }); // Update statistics when band status changes