From 126cbd315107f0d59c73e0fd12299458ddcff560 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 12 Feb 2025 14:27:53 +0100 Subject: [PATCH] fix: refs #7793 restore vnselect --- src/components/common/VnSelect.vue | 35 +++++++----------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index 950bb357b..339f90e0e 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -184,25 +184,7 @@ function findKeyInOptions() { if (!$props.options) return; return filter($props.modelValue, $props.options)?.length; } -function sortOptions(data) { - return 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); - }); -} function setOptions(data) { data = dataByOrder(data, $props.sortBy); myOptions.value = JSON.parse(JSON.stringify(data)); @@ -215,14 +197,13 @@ function filter(val, options) { if (!search) return options; - return sortOptions( - options.filter((row) => { - if ($props.filterOptions.length) { - return $props.filterOptions.some((prop) => { - const propValue = String(row[prop]).toLowerCase(); - return propValue.includes(search); - }); - } + return options.filter((row) => { + if ($props.filterOptions.length) { + return $props.filterOptions.some((prop) => { + const propValue = String(row[prop]).toLowerCase(); + return propValue.includes(search); + }); + } if (!row) return; const id = String(row[$props.optionValue]); @@ -235,7 +216,7 @@ function filter(val, options) { async function fetchFilter(val) { if (!$props.url) return; - const { fields, include, limit } = $props; + const { fields, include, sortBy, limit } = $props; const key = optionFilterValue.value ?? (new RegExp(/\d/g).test(val)