Enhance device filters: support label for dropdown options and improve SQL queries #1611

This commit is contained in:
Jokob @NetAlertX
2026-04-14 20:38:37 +00:00
parent 98a1ac1336
commit 285bd3ec22
3 changed files with 40 additions and 21 deletions

View File

@@ -436,22 +436,28 @@ function initFilters() {
if (existingFilter) {
// Add the unique columnValue to options if not already present
if (!existingFilter.options.includes(entry.columnValue)) {
existingFilter.options.push(entry.columnValue);
if (!existingFilter.options.some(opt => opt.value === entry.columnValue)) {
existingFilter.options.push({
value: entry.columnValue,
label: entry.columnLabel || entry.columnValue
});
}
} else {
// Create a new filter entry
transformed.filters.push({
column: entry.columnName,
headerKey: entry.columnHeaderStringKey,
options: [entry.columnValue]
options: [{
value: entry.columnValue,
label: entry.columnLabel || entry.columnValue
}]
});
}
});
// Sort options alphabetically for better readability
// Sort options alphabetically by label for better readability
transformed.filters.forEach(filter => {
filter.options.sort();
filter.options.sort((a, b) => a.label.localeCompare(b.label));
});
// Output the result

View File

@@ -10,9 +10,18 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/language/lang.php';
function renderFilterDropdown($headerKey, $columnName, $values) {
// Generate dropdown options
$optionsHtml = '<option value="" selected>All</option>'; // Default "All" option
foreach ($values as $value) {
$escapedValue = htmlspecialchars($value);
$optionsHtml .= '<option value="' . $escapedValue . '">' . $escapedValue . '</option>';
foreach ($values as $item) {
// Support both {value, label} objects and plain strings (backward compat)
if (is_array($item)) {
$val = $item['value'] ?? '';
$label = $item['label'] ?? $val;
} else {
$val = $item;
$label = $item;
}
$escapedValue = htmlspecialchars($val);
$escapedLabel = htmlspecialchars($label);
$optionsHtml .= '<option value="' . $escapedValue . '">' . $escapedLabel . '</option>';
}
// Generate the dropdown HTML