mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-15 22:51:37 -07:00
Enhance device filters: support label for dropdown options and improve SQL queries #1611
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user