From 0b076cec0ed1d8b741dbbf2570cd44b35ff9b57c Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Thu, 16 Apr 2026 09:05:48 +0000 Subject: [PATCH] ordering support for filters added #1616 --- front/devices.php | 48 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/front/devices.php b/front/devices.php index e08fdbc4..ac88b622 100755 --- a/front/devices.php +++ b/front/devices.php @@ -430,29 +430,35 @@ function initFilters() { filters: [] }; - // Group data by columnName - resultJSON.forEach(entry => { - const existingFilter = transformed.filters.find(filter => filter.column === entry.columnName); + // Build filters in the exact order of columnFilters + columnFilters.forEach(([columnName, headerKey]) => { + // Get matching entries for this column + const entries = resultJSON.filter(e => e.columnName === columnName); - if (existingFilter) { - // Add the unique columnValue to options if not already present - if (!existingFilter.options.some(opt => opt.value === entry.columnValue)) { - existingFilter.options.push({ - value: entry.columnValue, - label: entry.columnLabel || entry.columnValue - }); + if (entries.length === 0) return; + + // Build options (unique) + const optionsMap = new Map(); + + entries.forEach(entry => { + const value = entry.columnValue; + const label = entry.columnLabel || value; + + if (!optionsMap.has(value)) { + optionsMap.set(value, { value, label }); } - } else { - // Create a new filter entry - transformed.filters.push({ - column: entry.columnName, - headerKey: entry.columnHeaderStringKey, - options: [{ - value: entry.columnValue, - label: entry.columnLabel || entry.columnValue - }] - }); - } + }); + + const options = Array.from(optionsMap.values()); + + // Sort options alphabetically + options.sort((a, b) => a.label.localeCompare(b.label)); + + transformed.filters.push({ + column: columnName, + headerKey: headerKey, + options: options + }); }); // Sort options alphabetically by label for better readability