1
1
<template >
2
2
<div class =" row" >
3
3
<div class =" flex" >
4
- <VaInput iconColor =" primary" v-model =" searchForm.filter" clearable
5
- @update:modelValue =" (v: string) => emits('onFormChange', [['filter', v.length > 2 ? v : '']])"
4
+ <VaInput iconColor =" primary" v-model =" storeForm.filter" clearable @update:modelValue =" handleInputChange"
6
5
:placeholder =" t('buttons.search')" >
7
6
<template #appendInner >
8
7
<va-icon name =" search" />
63
62
</VaBadge >
64
63
</div >
65
64
<div class =" flex" >
66
- <VaBadge style =" z-index : 1 ;" overlap color =" info"
67
- :text =" searchForm.sort_column ? `${searchForm.sort_order} ${searchForm.sort_column}` : null" >
65
+ <VaBadge style =" z-index : 1 ;" overlap color =" info" :text =" sortDropdownText" >
68
66
<VaButtonDropdown preset =" primary" :round =" true" stickToEdges :closeOnContentClick =" false"
69
67
:label =" t('buttons.sort')" icon =" sort" >
70
68
<div class =" w-200" >
71
69
<div >
72
70
<VaSelect @update:modelValue =" (v: string) => emits('onFormChange', [['sort_column', v]])"
73
71
clearable class =" mt-2" :label =" t('search.sortColumn')" v-model =" searchForm.sort_column"
74
- :options = " columns.map(c => c.split('.').length > 0 ? c.split('.')[c.split('.').length - 1] : c) " />
72
+ textBy = " text " valueBy = " value " :options = " sortOptions " />
75
73
</div >
76
74
<div >
77
75
<VaSelect @update:modelValue =" (v: string) => emits('onFormChange', [['sort_order', v]])"
@@ -89,7 +87,6 @@ import { computed, ref, watchEffect } from 'vue';
89
87
import { DateRange , Filter } from ' ../../data/types'
90
88
import { useI18n } from ' vue-i18n' ;
91
89
92
-
93
90
const { t, locale } = useI18n ()
94
91
const props = defineProps <{ filters: Filter [], storeForm: Record <string , any >, columns: string [] }>()
95
92
@@ -100,16 +97,36 @@ const showFields = ref(props.columns.map(c => {
100
97
}
101
98
}))
102
99
103
-
104
100
const dateModels = ref ({ ... mapDates (props .storeForm ) })
105
101
106
102
const searchForm = ref ({ ... props .storeForm })
107
103
108
104
const activeFilters = computed (() => {
109
105
return Object .entries (searchForm .value )
106
+ .filter (([k , v ]) => k !== ' sort_column' && k !== ' sort_order' )
110
107
.filter (([k , v ]) => v ).length
111
108
})
112
109
110
+ const sortOptions = computed (() => {
111
+ return props .columns .map (c => {
112
+ const splittedField = c .split (' .' )
113
+ if (splittedField .length > 0 ) {
114
+ return { text: splittedField [splittedField .length - 1 ], value: c }
115
+ } else {
116
+ return { text: c , value: c }
117
+ }
118
+ })
119
+ })
120
+ const sortDropdownText = computed (() => {
121
+ if (searchForm .value .sort_column ) {
122
+ const splittedField = searchForm .value .sort_column .split (' .' )
123
+ if (splittedField .length > 0 ) {
124
+ return ` ${searchForm .value .sort_order } ${splittedField [splittedField .length - 1 ]} `
125
+ }
126
+ return ` ${searchForm .value .sort_order } ${searchForm .value .sort_column } `
127
+ }
128
+ return null
129
+ })
113
130
watchEffect (() => {
114
131
emits (' onShowFieldChange' , showFields .value .filter (f => f .show ).map (f => f .value ))
115
132
})
@@ -172,6 +189,19 @@ function isCheckBoxField(type: string) {
172
189
return type === ' checkbox' ;
173
190
};
174
191
192
+ const handleInputChange = debounce ((v : string ) => {
193
+ emits (' onFormChange' , [[' filter' , v .length > 2 ? v : ' ' ]]);
194
+ }, 300 ); // Adjust the delay (300ms) as needed
195
+
196
+ function debounce(fn : any , delay : number ) {
197
+ let timeoutId: any ;
198
+ return function (... args : any ) {
199
+ if (timeoutId ) clearTimeout (timeoutId );
200
+ timeoutId = setTimeout (() => {
201
+ fn (... args );
202
+ }, delay );
203
+ };
204
+ }
175
205
</script >
176
206
<style scoped>
177
207
.w-200 {
0 commit comments