@@ -4,14 +4,18 @@ import {
44 generateQueryFromObject ,
55 convertParamIfTypeInSchema ,
66 getRemovedKeyBetweenTwoObject ,
7- // getDefaultValueForParam
7+ getDefaultValueForParam
88} from "./utils/listPaginatedTools" ;
9+ import {
10+ getSortsArrayFromOrdering ,
11+ getOrderingFromSortArray
12+ } from "./utils/helpers" ;
913import cloneDeep from "lodash.clonedeep" ;
1014import isEqual from "lodash.isequal" ;
1115
12- import { ref , watch , nextTick } from 'vue-demi'
16+ import { ref , watch , nextTick , computed } from 'vue-demi'
1317import { useRoute , useRouter } from 'vue-router'
14- import { GenericDictionnary , VDUSConfiguration } from "./utils/VDUSTypes"
18+ import { GenericDictionnary , VDUSConfiguration , VuetifyOptions } from "./utils/VDUSTypes"
1519
1620/*
1721DOC here on params and return value
@@ -50,6 +54,45 @@ export default function useDatatableUrlSync(form: GenericDictionnary, fetchDatas
5054 localQuery = triggerSearchIfNeeded ( isFilter , getDatas ) ;
5155 } , configurations ?. debounceTime || 0 ) ;
5256
57+ // ----------------------------- COMPUTED ---------------------------
58+
59+ const vuetifyOptions = computed ( {
60+ get : ( ) :VuetifyOptions => {
61+ let vuetifyOptions :VuetifyOptions = {
62+ page : 1 ,
63+ itemsPerPage : 10 ,
64+ sortBy : [ ] ,
65+ sortDesc : [ ] ,
66+ groupBy : [ ] ,
67+ groupDesc : [ ] ,
68+ multiSort : false ,
69+ mustSort : false
70+ } ;
71+
72+ vuetifyOptions . page = options . page ?? getDefaultValueForParam ( "page" , formSchema ) ;
73+ vuetifyOptions . itemsPerPage = options . page_size ?? getDefaultValueForParam ( "page_size" , formSchema ) ;
74+
75+ let ordering :Array < string > =
76+ Array . isArray ( options . ordering ) &&
77+ options . ordering . length > 0
78+ ? options . ordering
79+ : getDefaultValueForParam ( "ordering" , formSchema ) ;
80+
81+ let { sortBy, sortDesc } = getSortsArrayFromOrdering ( ordering ) ;
82+
83+ vuetifyOptions . sortBy = sortBy ;
84+ vuetifyOptions . sortDesc = sortDesc ;
85+
86+ return vuetifyOptions ;
87+ } ,
88+ set : ( newOptions :VuetifyOptions ) => {
89+ // As we do not define options by default, to avoid reload from other component we doesn't want, we need to set data because they are not reactive
90+ options . page = newOptions . page ;
91+ options . page_size = newOptions . itemsPerPage ;
92+ options . ordering = getOrderingFromSortArray ( newOptions . sortBy , newOptions . sortDesc )
93+ }
94+ } )
95+
5396 // ----------------------------- WATCH ------------------------------
5497 watch ( form , ( ) => {
5598 debounceSearch ( true ) ;
0 commit comments