Skip to content

Commit 0b076ce

Browse files
committed
ordering support for filters added #1616
1 parent a5b4f2a commit 0b076ce

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

front/devices.php

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -430,29 +430,35 @@ function initFilters() {
430430
filters: []
431431
};
432432

433-
// Group data by columnName
434-
resultJSON.forEach(entry => {
435-
const existingFilter = transformed.filters.find(filter => filter.column === entry.columnName);
436-
437-
if (existingFilter) {
438-
// Add the unique columnValue to options if not already present
439-
if (!existingFilter.options.some(opt => opt.value === entry.columnValue)) {
440-
existingFilter.options.push({
441-
value: entry.columnValue,
442-
label: entry.columnLabel || entry.columnValue
443-
});
433+
// Build filters in the exact order of columnFilters
434+
columnFilters.forEach(([columnName, headerKey]) => {
435+
// Get matching entries for this column
436+
const entries = resultJSON.filter(e => e.columnName === columnName);
437+
438+
if (entries.length === 0) return;
439+
440+
// Build options (unique)
441+
const optionsMap = new Map();
442+
443+
entries.forEach(entry => {
444+
const value = entry.columnValue;
445+
const label = entry.columnLabel || value;
446+
447+
if (!optionsMap.has(value)) {
448+
optionsMap.set(value, { value, label });
444449
}
445-
} else {
446-
// Create a new filter entry
447-
transformed.filters.push({
448-
column: entry.columnName,
449-
headerKey: entry.columnHeaderStringKey,
450-
options: [{
451-
value: entry.columnValue,
452-
label: entry.columnLabel || entry.columnValue
453-
}]
454-
});
455-
}
450+
});
451+
452+
const options = Array.from(optionsMap.values());
453+
454+
// Sort options alphabetically
455+
options.sort((a, b) => a.label.localeCompare(b.label));
456+
457+
transformed.filters.push({
458+
column: columnName,
459+
headerKey: headerKey,
460+
options: options
461+
});
456462
});
457463

458464
// Sort options alphabetically by label for better readability

0 commit comments

Comments
 (0)