@@ -70,18 +70,21 @@ export function usePaginatedData(
7070 }
7171
7272 function fetchData ( ) {
73- window . history . replaceState ( null , '' , window . location . pathname ) ;
7473 return new Promise ( ( resolve , reject ) => {
7574 processing . value = true ;
76- router . reload ( {
77- only : [ 'request' , ... new Set ( only ) ] ,
75+ router . visit ( window . location . pathname , {
76+ method : 'get' ,
7877 data : {
7978 filters : filters . value as any ,
8079 ...pagination . value ,
8180 sortField : sorting . value . field ,
8281 sortOrder : sorting . value . order ,
8382 } ,
83+ preserveState : true ,
84+ preserveUrl : false ,
8485 showProgress : true ,
86+ replace : true ,
87+ only : [ 'request' , ...new Set ( only ) ] ,
8588 onSuccess : ( page ) => {
8689 resolve ( page ) ;
8790 } ,
@@ -96,7 +99,11 @@ export function usePaginatedData(
9699 }
97100
98101 function paginate ( event : PageState | DataTablePageEvent ) {
99- pagination . value . page = event . page + 1 ;
102+ if ( event . rows != pagination . value . rows ) {
103+ pagination . value . page = 1 ;
104+ } else {
105+ pagination . value . page = event . page + 1 ;
106+ }
100107 pagination . value . rows = event . rows ;
101108 fetchData ( ) . then ( ( ) => {
102109 scrollToTop ( ) ;
@@ -111,9 +118,6 @@ export function usePaginatedData(
111118 }
112119
113120 function reset ( ) {
114- // Alternatively just use: router.get(window.location.pathname);
115- // Caveat to the above approach, we would lose state from our page not related to pagination/filtering/sorting
116-
117121 const defaultFilters = cloneDeep ( initialFilters ) ;
118122 Object . keys ( defaultFilters ) . forEach ( ( key ) => {
119123 filters . value [ key ] . value = defaultFilters [ key ] . value ;
@@ -127,8 +131,16 @@ export function usePaginatedData(
127131 page : 1 ,
128132 rows : initialsRows ,
129133 } ;
130- fetchData ( ) . then ( ( ) => {
131- window . history . replaceState ( null , '' , window . location . pathname ) ;
134+ fetchData ( ) ;
135+ }
136+
137+ function hardReset ( ) {
138+ router . visit ( window . location . pathname , {
139+ method : 'get' ,
140+ preserveUrl : false ,
141+ showProgress : true ,
142+ replace : true ,
143+ only : [ 'request' , ...new Set ( only ) ] ,
132144 } ) ;
133145 }
134146
@@ -203,6 +215,7 @@ export function usePaginatedData(
203215 paginate,
204216 filter,
205217 reset,
218+ hardReset,
206219 parseUrlParams,
207220 } ;
208- }
221+ }
0 commit comments