#7793 - sortByWeight #763

Open
jsegarra wants to merge 10 commits from 7793_sortByWeight into dev
1 changed files with 18 additions and 1 deletions
Showing only changes of commit 3476b4807f - Show all commits

View File

@ -86,6 +86,10 @@ const $props = defineProps({
type: Boolean,
default: false,
},
sortByWeight: {
Outdated
Review

Esta propiedad no se esta usando?

Esta propiedad no se esta usando?
type: Boolean,
default: false,
},
});
const { validations } = useValidator();
const requiredFieldRule = (val) => validations().required($attrs.required, val);
@ -186,11 +190,24 @@ async function fetchFilter(val) {
$props.exprBuilder && Object.assign(where, $props.exprBuilder(key, val));
const fetchOptions = { where, include, limit };
if (fields) fetchOptions.fields = fields;
if (sortBy) fetchOptions.order = sortBy;
if (sortBy) {
let sort = sortBy;
if (typeof sort === 'string') sort = [getOrderCaseString(key, val), sortBy];
else sort = [getOrderCaseString(key, val), ...sortBy];
fetchOptions.order = sort;
}
return dataRef.value.fetch(fetchOptions);
}
function getOrderCaseString(prop, value) {
return `CASE
WHEN ${prop} LIKE '${value}%' THEN 1
WHEN ${prop} LIKE '%${value}%' THEN 2
ELSE 3
END, ${prop} DESC`;
}
async function filterHandler(val, update) {
if (!val && lastVal.value === val) {
lastVal.value = val;