11import type { QTableProps } from "quasar"
22import type { LocationQueryValue } from "vue-router"
3+ import dayjs from "dayjs"
34
45const fieldTypes = ref <
56 {
@@ -27,6 +28,11 @@ export type ComparatorType = {
2728 suffix : string
2829}
2930
31+ export type ColumnType = {
32+ name : string
33+ type : string
34+ }
35+
3036const comparatorTypes = ref < ComparatorType [ ] > ( [
3137 {
3238 label : 'Égal à' ,
@@ -220,10 +226,15 @@ const sanitizeSearchString = (search: string) => {
220226 return search
221227}
222228
223- const getSearchString = ( columns : Ref < QTableProps [ 'columns' ] & { type : string } [ ] > , search : LocationQueryValue | LocationQueryValue [ ] , fieldLabel : string ) => {
229+ const getSearchString = (
230+ columns : Ref < QTableProps [ 'columns' ] & { type : string } [ ] > ,
231+ search : LocationQueryValue | LocationQueryValue [ ] ,
232+ fieldLabel : string ,
233+ columnTypes ?: Ref < ColumnType [ ] >
234+ ) => {
224235 const field = columns . value ?. find ( ( f ) => f . name === fieldLabel . replace ( '[]' , '' ) )
225- console . log ( 'field' , fieldLabel , field )
226236 if ( ! field ) return ''
237+ const fieldType = columnTypes ?. value . find ( ( col ) => col . name === fieldLabel . replace ( '[]' , '' ) ) ?. type || 'text'
227238 // if (field.type === 'multiple') {
228239 // const searchArray = Array.isArray(search) ? search : [search]
229240 // return searchArray
@@ -237,9 +248,10 @@ const getSearchString = (columns: Ref<QTableProps['columns'] & { type: string }[
237248 // if (Array.isArray(search)) {
238249 // return search.join(' ou ')
239250 // }
240- // if (field?.type === 'date') {
241- // return dayjs(search).format('DD/MM/YYYY')
242- // }
251+ console . log ( 'fieldType' , fieldType , fieldLabel , search , columnTypes )
252+ if ( fieldType === 'date' ) {
253+ return dayjs ( search ! . toString ( ) ) . format ( 'DD/MM/YYYY' )
254+ }
243255 return sanitizeSearchString ( search ! . toString ( ) )
244256}
245257
@@ -279,7 +291,7 @@ const getComparatorObject = (comparatorSign: string, search?: string) => {
279291 return candidates [ 0 ]
280292}
281293
282- export function useFiltersQuery ( columns : Ref < QTableProps [ 'columns' ] & { type : string } [ ] > ) {
294+ export function useFiltersQuery ( columns : Ref < QTableProps [ 'columns' ] & { type : string } [ ] > , columnTypes ?: Ref < ColumnType [ ] > ) {
283295 const $route = useRoute ( )
284296
285297 const countFilters = computed ( ( ) => {
@@ -304,7 +316,7 @@ export function useFiltersQuery(columns: Ref<QTableProps['columns'] & { type: st
304316
305317 const label = getLabelByName ( columns , extract . field ) || extract . field
306318 const rawValue = `${ $route . query [ key ] } `
307- const search = getSearchString ( columns , $route . query [ key ] , extract . field )
319+ const search = getSearchString ( columns , $route . query [ key ] , extract . field , columnTypes )
308320
309321 if ( ! search || search === '' ) {
310322 console . warn ( `Invalid search for filter key: ${ key } ${ filteredKey } ` , {
0 commit comments