diff --git a/src/components/common/VnCard.vue b/src/components/common/VnCard.vue index 17fa74317b..a352a68494 100644 --- a/src/components/common/VnCard.vue +++ b/src/components/common/VnCard.vue @@ -20,6 +20,7 @@ const props = defineProps({ searchUrl: { type: String, default: undefined }, searchbarLabel: { type: String, default: '' }, searchbarInfo: { type: String, default: '' }, + searchKey: { type: String, default: 'search' }, searchCustomRouteRedirect: { type: String, default: undefined }, searchRedirect: { type: Boolean, default: true }, searchMakeFetch: { type: Boolean, default: true }, @@ -72,6 +73,7 @@ if (props.baseUrl) { :info="props.searchbarInfo" :custom-route-redirect-name="searchCustomRouteRedirect" :redirect="searchRedirect" + :search-key="searchKey" /> diff --git a/src/components/ui/VnSearchbar.vue b/src/components/ui/VnSearchbar.vue index 0c7a8a3f61..6dd2f5f4b3 100644 --- a/src/components/ui/VnSearchbar.vue +++ b/src/components/ui/VnSearchbar.vue @@ -61,15 +61,23 @@ const props = defineProps({ }, customRouteRedirectName: { type: String, - default: '', + default: null, }, makeFetch: { type: Boolean, default: true, }, + searchKey: { + type: String, + default: 'search', + }, + isQueryFilter: { + type: Boolean, + default: false, + }, }); -const searchText = ref(''); +const searchText = ref(); let arrayDataProps = { ...props }; if (props.redirect) arrayDataProps = { @@ -105,13 +113,26 @@ async function search() { ); arrayData.reset(['skip', 'page']); - if (props.makeFetch) - await arrayData.applyFilter({ - params: { - ...Object.fromEntries(staticParams), - search: searchText.value, - }, - }); + if (props.isQueryFilter) { + if (props.makeFetch) + await arrayData.applyFilter({ + params: { + ...Object.fromEntries(staticParams), + }, + filter: { + where: { + name: searchText.value == '' ? undefined : searchText.value, + }, + }, + }); + } else { + if (props.makeFetch) + await arrayData.applyFilter({ + params: { + ...Object.fromEntries(staticParams), + }, + }); + } }