#7136 - Enable paginate event in VnSelectFilter #255
|
@ -66,7 +66,7 @@ const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
|
|||
|
||||
const { optionLabel, optionValue, optionFilter, options, modelValue } = toRefs($props);
|
||||
const myOptions = ref([]);
|
||||
const myOptionsFiltered = ref([]);
|
||||
// const myOptionsFiltered = ref([]);
|
||||
|
||||
const myOptionsOriginal = ref([]);
|
||||
const vnSelectRef = ref();
|
||||
const dataRef = ref();
|
||||
|
@ -76,6 +76,7 @@ const selectValue = computed({
|
|||
return $props.modelValue;
|
||||
},
|
||||
set(value) {
|
||||
arrayData.store.page.value = 0;
|
||||
emit('update:modelValue', value);
|
||||
},
|
||||
});
|
||||
|
@ -103,8 +104,7 @@ onMounted(async () => {
|
|||
setOptions(data);
|
||||
return;
|
||||
}
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
De primeras diria que esta linea no hace falta, dado que la primera ja lo hace De primeras diria que esta linea no hace falta, dado que la primera ja lo hace
jsegarra
commented
Pero quiero evitar que haga fetch Pero quiero evitar que haga fetch
Un caso de uso sería: se lo declaro en el componente o una variable
alexm
commented
`updateRouter: false` sino podrá cosas en la url
|
||||
if ($props.options) setOptions($props.options);
|
||||
else fetchFilter($props.modelValue);
|
||||
if (!$props.options) fetchFilter($props.modelValue);
|
||||
alexm
commented
Esta parte solo debe hacerla si hay url. Y por como esta ahora ya habria hecho la peticion al entrar en Esta parte solo debe hacerla si hay url. Y por como esta ahora ya habria hecho la peticion al entrar en `if (useURL.value)`
jsegarra
commented
Lo cambio para dejarlo asi Lo cambio para dejarlo asi
if (!$props.options) fetchFilter($props.modelValue);
|
||||
});
|
||||
|
||||
watch(modelValue, (newValue) => {
|
||||
|
@ -136,37 +136,31 @@ function filter(val, options) {
|
|||
return optionsFiltered;
|
||||
}
|
||||
|
||||
function buildwhere(val) {
|
||||
async function fetchFilter(val) {
|
||||
if (!useURL.value || !dataRef.value) return;
|
||||
|
||||
let key = optionLabel.value;
|
||||
|
||||
const { fields, sortBy, limit } = $props;
|
||||
let key = null;
|
||||
if (new RegExp(/\d/g).test(val)) key = optionFilter.value ?? optionValue.value;
|
||||
|
||||
const where = { ...{ [key]: { like: `%${val}%` } }, ...$props.where };
|
||||
return where;
|
||||
}
|
||||
async function fetchFilter(val) {
|
||||
const { fields, sortBy, limit } = $props;
|
||||
const where = buildwhere(val);
|
||||
if (!dataRef.value) return;
|
||||
return dataRef.value.fetch({ fields, where, order: sortBy, limit });
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Por como esta useArrayData, fetch no acepta los datos por paramtros. Solo Por como esta useArrayData, fetch no acepta los datos por paramtros. Solo `{ append = false, updateRouter = true }`
|
||||
}
|
||||
|
||||
async function filterHandler(val, update) {
|
||||
if (!$props.defaultFilter) return update();
|
||||
alexm
commented
Si de por si solo entra en fetchFilter si hay url, no hace falta separar la construccion del where en una funcion apart, que solo se usa en un sitio Si de por si solo entra en fetchFilter si hay url, no hace falta separar la construccion del where en una funcion apart, que solo se usa en un sitio
jsegarra
commented
Vale, lo debí separar para otra situación que acabé borrando y esto se quedó así Vale, lo debí separar para otra situación que acabé borrando y esto se quedó así
Lo limipio
|
||||
let newOptions = [];
|
||||
if (myOptionsFiltered.value.length > 0) {
|
||||
newOptions = filter(val, myOptionsFiltered.value);
|
||||
myOptionsFiltered.value = [];
|
||||
if (myOptions.value.length > 0) {
|
||||
newOptions = filter(val, myOptions.value);
|
||||
myOptions.value = [];
|
||||
} else newOptions = filter(val, myOptionsOriginal.value);
|
||||
if (useURL.value && myOptions.value.length < 1) {
|
||||
arrayData.store.skip = 0;
|
||||
arrayData.store.filter.skip = 0;
|
||||
arrayData.store.filter.where = { [optionFilter.value]: val };
|
||||
arrayData.store.filter.where = { [optionFilter.value]: val, ...$props.where };
|
||||
const { data } = await arrayData.fetch({ append: false });
|
||||
newOptions = data;
|
||||
myOptionsFiltered.value = data;
|
||||
myOptions.value = data;
|
||||
}
|
||||
update(
|
||||
() => {
|
||||
|
|
Por como estaba creo recordar que
myOptions
era la variable para las opciones filtradas ymyOptionsOriginal
para las originales.myOptionsFiltered
para que seria? Puede sermyOptions
?Me he dado cuenta que la necesidad de esa variable no cubre otro caso de uso asi que la elimino