@@ -30,6 +30,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
3030 v-model ='filter.operator'
3131 label ='Opérateur'
3232 :options ='availableComparators'
33+ :readonly ='!filter.key'
3334 option-value ='value'
3435 option-label ='label'
3536 dense
@@ -54,7 +55,8 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
5455 label ='Valeur'
5556 :prefix ="comparator?.prefix"
5657 :suffix ="comparator?.suffix"
57- :type ='searchInputType'
58+ :readonly ='!filter.operator'
59+ :type ='searchInputType === "date" ? "datetime-local" : searchInputType'
5860 @keydown.enter.prevent ="writeFilter(filter)"
5961 dense
6062 outlined
@@ -67,9 +69,11 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
6769 :prefix ="comparator?.prefix"
6870 :suffix ="comparator?.suffix"
6971 :type ='searchInputType'
72+ :readonly ='!filter.operator'
7073 @keydown.enter.prevent ="writeFilter(filter)"
7174 :options ="optionsMapping"
7275 emit-value
76+ use-chips
7377 map-options
7478 dense
7579 outlined
@@ -79,6 +83,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
7983 v-show ="comparator?.multiplefields && comparator?.querySign === '<<'"
8084 v-model ="filter.min"
8185 :type ='searchInputType'
86+ :readonly ='!filter.operator'
8287 label ="Minimum"
8388 clearable
8489 dense
@@ -89,6 +94,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
8994 v-show ="comparator?.multiplefields && comparator?.querySign === '<<'"
9095 v-model ="filter.max"
9196 :type ='searchInputType'
97+ :readonly ='!filter.operator'
9298 label ="Maximum"
9399 clearable
94100 dense
@@ -103,6 +109,7 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
103109 :suffix ="comparator?.suffix"
104110 :type ='searchInputType'
105111 :options ="optionsMapping"
112+ :readonly ='!filter.operator'
106113 input-debounce ="100"
107114 new-value-mode ="add-unique"
108115 emit-value
@@ -129,11 +136,12 @@ q-card.transparent(style='min-width: 40vw; max-width: 80vw')
129136
130137<script lang="ts">
131138import type { QTableProps } from ' quasar'
139+ import dayjs from ' dayjs'
132140
133141type Filter = {
134142 key: string
135143 operator: string
136- value: string
144+ value: string | number | undefined
137145
138146 min? : string
139147 max? : string
@@ -180,10 +188,14 @@ export default defineNuxtComponent({
180188 },
181189 ' filter.operator' : {
182190 handler() {
183- this .filter .value = ' '
184- this .filter .min = ' '
185- this .filter .max = ' '
186- this .filter .items = []
191+ if (this .comparator ?.multiplefields ) {
192+ this .filter .value = undefined
193+ } else if (this .filter .items && this .filter .items .length > 0 ) {
194+ this .filter .items = []
195+ } else {
196+ this .filter .min = ' '
197+ this .filter .max = ' '
198+ }
187199 },
188200 },
189201 },
@@ -260,11 +272,22 @@ export default defineNuxtComponent({
260272 }
261273 }
262274
275+ let initialValue = ref <string | number | undefined >(undefined )
276+ const operator = detectInitialOperator ()
277+ const comp = comparatorTypes .value .find ((comp ) => comp .value === operator )
278+
279+ if (comp ?.type .includes (' date' ) && initialFilter .value ) {
280+ const dateValue = dayjs (initialFilter .value ).format (' YYYY-MM-DDTHH:mm' )
281+ initialValue .value = dateValue
282+ } else {
283+ initialValue .value = stripPrefixSuffix (initialFilter ?.value ) || undefined
284+ }
285+
263286 const fieldType = ref <string >()
264287 const filter = ref <Filter >({
288+ operator ,
265289 key: initialFilter ?.field ?.replace (' []' , ' ' ) || ' ' ,
266- operator: detectInitialOperator (),
267- value: stripPrefixSuffix (initialFilter ?.value ) || ' ' ,
290+ value: initialValue .value ,
268291
269292 min: ' ' ,
270293 max: ' ' ,
@@ -300,7 +323,7 @@ export default defineNuxtComponent({
300323 this .columnsType .forEach ((col ) => {
301324 if (col .name === this .filter .key && col .valueMapping ) {
302325 Object .entries (col .valueMapping ).forEach (([key , val ]) => {
303- mapping .push ({ label: val , value: key })
326+ mapping .push ({ label: val + ' ( ' + key + ' ) ' , value: key })
304327 })
305328 }
306329 })
@@ -309,9 +332,9 @@ export default defineNuxtComponent({
309332 },
310333 },
311334 mounted() {
312- console .log (' comparator' , this .comparator )
313- console .log (' optionsMapping' , this .optionsMapping )
314- console .log (' this.columnsType' , this .columnsType )
335+ // console.log('comparator', this.comparator)
336+ // console.log('optionsMapping', this.optionsMapping)
337+ // console.log('this.columnsType', this.columnsType)
315338 this .fieldType = this .columnsType .find ((col ) => col .name === this .filter .key )?.type || ' text'
316339 },
317340})
0 commit comments