#7793 - sortByWeight #763

Open
jsegarra wants to merge 10 commits from 7793_sortByWeight into dev
1 changed files with 17 additions and 0 deletions
Showing only changes of commit 8f963ab78a - Show all commits

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));
}