#7793 - sortByWeight #763

Closed
jsegarra wants to merge 11 commits from 7793_sortByWeight into dev
1 changed files with 8 additions and 27 deletions
Showing only changes of commit 126cbd3151 - Show all commits

View File

@ -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) {
Outdated
Review

Esto funciona asi tal cual?

Esto funciona asi tal cual?

No, esto se elimina en favor del método sort
Grcias

No, esto se elimina en favor del método sort Grcias
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)