perf: refs #7793 imrpove sort data method
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javier Segarra 2024-10-09 01:45:38 +02:00
parent ad76d81908
commit 8f963ab78a
1 changed files with 17 additions and 0 deletions

View File

@ -139,6 +139,23 @@ function findKeyInOptions() {
}
function setOptions(data) {
data = data.sort((a, b) => {
const search = lastVal.value?.toString()?.toLowerCase();
const aValue = String(a[$props.optionLabel]).toLowerCase();
const bValue = String(b[$props.optionLabel]).toLowerCase();
const aIndex = aValue.indexOf(search);
const bIndex = bValue.indexOf(search);
const aPriority = aIndex === 0 ? 0 : aIndex > 0 ? 1 : 2;
const bPriority = bIndex === 0 ? 0 : bIndex > 0 ? 1 : 2;
if (aPriority !== bPriority) {
return aPriority - bPriority;
}
return aValue.localeCompare(bValue);
});
myOptions.value = JSON.parse(JSON.stringify(data));
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
}