fix(VnFilterPanel): emit userParams better #607
|
@ -41,6 +41,7 @@ async function orderBy(name, direction) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!direction) return await arrayData.deleteOrder(name);
|
if (!direction) return await arrayData.deleteOrder(name);
|
||||||
|
console.log('name, direction: ', name, direction);
|
||||||
await arrayData.addOrder(name, direction);
|
await arrayData.addOrder(name, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ watch(
|
||||||
|
|
||||||
const isTableMode = computed(() => mode.value == TABLE_MODE);
|
const isTableMode = computed(() => mode.value == TABLE_MODE);
|
||||||
|
|
||||||
function setUserParams(watchedParams) {
|
function setUserParams(watchedParams, watchedOrder) {
|
||||||
if (!watchedParams) return;
|
if (!watchedParams) return;
|
||||||
|
|
||||||
if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams);
|
if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams);
|
||||||
|
@ -163,7 +163,7 @@ function setUserParams(watchedParams) {
|
||||||
? JSON.parse(watchedParams?.filter)
|
? JSON.parse(watchedParams?.filter)
|
||||||
: watchedParams?.filter;
|
: watchedParams?.filter;
|
||||||
const where = filter?.where;
|
const where = filter?.where;
|
||||||
const order = filter?.order;
|
const order = watchedOrder ?? filter?.order;
|
||||||
|
|
||||||
watchedParams = { ...watchedParams, ...where };
|
watchedParams = { ...watchedParams, ...where };
|
||||||
delete watchedParams.filter;
|
delete watchedParams.filter;
|
||||||
|
|
|
@ -82,23 +82,28 @@ onMounted(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function setUserParams(watchedParams) {
|
function setUserParams(watchedParams) {
|
||||||
if (!watchedParams) return;
|
if (!watchedParams || Object.keys(watchedParams).length == 0) return;
|
||||||
jorgep marked this conversation as resolved
|
|||||||
|
|
||||||
if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams);
|
if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams);
|
||||||
|
if (typeof watchedParams?.filter == 'string')
|
||||||
|
watchedParams.filter = JSON.parse(watchedParams.filter);
|
||||||
|
|
||||||
watchedParams = { ...watchedParams, ...watchedParams.filter?.where };
|
watchedParams = { ...watchedParams, ...watchedParams.filter?.where };
|
||||||
|
const order = watchedParams.filter?.order;
|
||||||
|
|
||||||
delete watchedParams.filter;
|
delete watchedParams.filter;
|
||||||
userParams.value = { ...userParams.value, ...watchedParams };
|
userParams.value = { ...userParams.value, ...sanitizer(watchedParams) };
|
||||||
emit('setUserParams', userParams.value);
|
emit('setUserParams', userParams.value, order);
|
||||||
jorgep marked this conversation as resolved
alexm
commented
Si no emite el order, cuando se actualiza la url quita los ordenes del VnTable Si no emite el order, cuando se actualiza la url quita los ordenes del VnTable
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
alexm marked this conversation as resolved
jorgep
commented
Puedes crear un watch para observar route.query[$props.searchUrl] y arrayData.store.userParams Tipo esto: Puedes crear un watch para observar **route.query[$props.searchUrl]** y **arrayData.store.userParams**
Tipo esto:
`watch(
() => [route.query[$props.searchUrl], arrayData.store.userParams],
([newSearchUrl, newUserParams], [oldSearchUrl, oldUserParams]) => {
if (newSearchUrl || oldSearchUrl) {
setUserParams(newSearchUrl);
}
if (newUserParams || oldUserParams) {
setUserParams(newUserParams);
}
}
);`
|
|||||||
() => route.query[$props.searchUrl],
|
() => route.query[$props.searchUrl],
|
||||||
(val) => setUserParams(val)
|
(val, oldValue) => (val || oldValue) && setUserParams(val)
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => arrayData.store.userParams,
|
() => arrayData.store.userParams,
|
||||||
(val) => setUserParams(val)
|
(val, oldValue) => (val || oldValue) && setUserParams(val)
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
Loading…
Reference in New Issue
Hay casos que es objeto vacío y no queremos emitirlo