dropdown in alphabetical order
This commit is contained in:
parent
497ebda65a
commit
35021e9d9b
File diff suppressed because one or more lines are too long
@ -15,17 +15,31 @@ try {
|
||||
$endpoint = 'MoltiplicatorePrezzi';
|
||||
|
||||
// Opzionale: parametri OData ($top, $filter, $orderby, ecc.)
|
||||
$options = []; // es: ['$top' => 100]
|
||||
$options = [
|
||||
'$orderby' => 'Descrizione asc'
|
||||
];
|
||||
|
||||
// Debug: salva URL usata
|
||||
$base_url = 'https://93.43.5.102/limsapi/api/odata/';
|
||||
$query = http_build_query($options);
|
||||
$queryParts = [];
|
||||
foreach ($options as $k => $v) {
|
||||
// mantieni il $ nella chiave, encoda solo il valore
|
||||
$queryParts[] = $k . '=' . rawurlencode($v);
|
||||
}
|
||||
$query = implode('&', $queryParts);
|
||||
$full_url = $base_url . $endpoint . ($query ? '?' . $query : '');
|
||||
file_put_contents(__DIR__ . '/last_url.txt', $full_url . PHP_EOL, FILE_APPEND);
|
||||
|
||||
// Chiamata API
|
||||
$data = $api->get($endpoint, $options);
|
||||
|
||||
// ✅ Force sort locally by "Descrizione" (A→Z)
|
||||
if (isset($data['value']) && is_array($data['value'])) {
|
||||
usort($data['value'], function ($a, $b) {
|
||||
$da = isset($a['Descrizione']) ? trim((string)$a['Descrizione']) : '';
|
||||
$db = isset($b['Descrizione']) ? trim((string)$b['Descrizione']) : '';
|
||||
return strcasecmp($da, $db); // case-insensitive alphabetical
|
||||
});
|
||||
}
|
||||
// Salva il JSON in locale
|
||||
file_put_contents(__DIR__ . '/moltiplicatori_prezzo_response.json', json_encode($data, JSON_PRETTY_PRINT));
|
||||
|
||||
|
||||
@ -1846,6 +1846,10 @@ function fixedDefaultValue(array $f): string
|
||||
}
|
||||
|
||||
const items = dropdownData[fieldId];
|
||||
// ✅ Sort alphabetically by Valore (A→Z)
|
||||
items.sort((a, b) => String(a.Valore || '').localeCompare(String(b.Valore || ''), 'it', {
|
||||
sensitivity: 'base'
|
||||
}));
|
||||
const valToSelect = currentValue || selectedValue;
|
||||
|
||||
if (items.length > 12) {
|
||||
@ -2319,6 +2323,12 @@ function fixedDefaultValue(array $f): string
|
||||
id: item[config.idKey],
|
||||
text: (item.Codice ? item.Codice + ' - ' : '') + (item[config.textKey] || 'Senza nome')
|
||||
}));
|
||||
|
||||
// ✅ Sort alphabetically by text
|
||||
results.sort((a, b) => String(a.text || '').localeCompare(String(b.text || ''), 'it', {
|
||||
sensitivity: 'base'
|
||||
}));
|
||||
|
||||
fixedFieldDataCache[cacheKey] = results;
|
||||
return results;
|
||||
} catch (err) {
|
||||
@ -2378,6 +2388,10 @@ function fixedDefaultValue(array $f): string
|
||||
id: item[config.idKey],
|
||||
text: (item.Codice ? item.Codice + ' - ' : '') + (item[config.textKey] || 'Senza nome')
|
||||
}));
|
||||
// ✅ Sort alphabetically by text
|
||||
results.sort((a, b) => String(a.text || '').localeCompare(String(b.text || ''), 'it', {
|
||||
sensitivity: 'base'
|
||||
}));
|
||||
} else {
|
||||
results = await loadFixedFieldData(fieldKey);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user