From 4cfc278106e82ab56de21bd25d46b48da48c79a9 Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Mon, 1 Dec 2025 08:57:14 -0500 Subject: [PATCH] refactor: improve sorting logic for server statistics by adding numeric handling for specific columns and normalizing NaN values --- .../Proxmox/views/statistics.blade.php | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/extensions/Servers/Proxmox/views/statistics.blade.php b/extensions/Servers/Proxmox/views/statistics.blade.php index 4442bc8f4..c22f829c7 100644 --- a/extensions/Servers/Proxmox/views/statistics.blade.php +++ b/extensions/Servers/Proxmox/views/statistics.blade.php @@ -4014,8 +4014,15 @@ var aVal = a.row.getAttribute(dataAttr) || ''; var bVal = b.row.getAttribute(dataAttr) || ''; - // Check if this is a date column (date-time, start-time, or end-time) + // Column helpers var isDateColumn = column === 'date-time' || column === 'start-time' || column === 'end-time'; + // Treat these columns as numeric even if stored as strings/data-attributes + var isNumericColumn = ( + column === 'traffic' || + column === 'duration' || + column === 'bytes' || + column === 'size' + ); if (isDateColumn) { // Handle date values (format: YYYY-MM-DD HH:mm:ss) @@ -4080,11 +4087,27 @@ } } - // Handle numeric values (for duration, etc.) - var aNum = parseFloat(aVal); - var bNum = parseFloat(bVal); - if (!isNaN(aNum) && !isNaN(bNum) && aVal !== '' && bVal !== '') { - return component.sortDirection === 'asc' ? aNum - bNum : bNum - aNum; + // Handle numeric values (for traffic, duration, etc.) + if (isNumericColumn) { + var aNum = parseFloat(aVal); + var bNum = parseFloat(bVal); + + // Normalise NaN and empty values to 0 so rows still participate in sort + if (isNaN(aNum)) aNum = 0; + if (isNaN(bNum)) bNum = 0; + + if (component.sortDirection === 'asc') { + return aNum - bNum; + } else { + return bNum - aNum; + } + } else { + // Generic numeric handling for other cases where both values are valid numbers + var aNumGeneric = parseFloat(aVal); + var bNumGeneric = parseFloat(bVal); + if (!isNaN(aNumGeneric) && !isNaN(bNumGeneric) && aVal !== '' && bVal !== '') { + return component.sortDirection === 'asc' ? aNumGeneric - bNumGeneric : bNumGeneric - aNumGeneric; + } } // Handle string values