@@ -115,14 +115,28 @@ functionsToRunOnDataTablesDrawEvent: [],
115115 { fn = fn[ arr[i] ]; }
116116 fn .apply (window , args);
117117 },
118- updateUrl : function (new_url ) {
119- url_start = " {{ url ($crud -> route ) } }" ;
120- url_end = new_url .replace (url_start, ' ' );
121- url_end = url_end .replace (' /search' , ' ' );
122- new_url = url_start + url_end;
123-
124- window .history .pushState ({}, ' ' , new_url);
125- localStorage .setItem (' {{ Str:: slug ($crud -> getRoute ()) } } _list_url' , new_url);
118+ updateUrl : function (url ) {
119+ let urlStart = " {{ url ($crud -> route ) } }" ;
120+ let urlEnd = url .replace (urlStart, ' ' );
121+ urlEnd = urlEnd .replace (' /search' , ' ' );
122+ let newUrl = urlStart + urlEnd;
123+ let tmpUrl = newUrl .split (" ?" )[0 ],
124+ params_arr = [],
125+ queryString = (newUrl .indexOf (" ?" ) !== - 1 ) ? newUrl .split (" ?" )[1 ] : false ;
126+
127+ // exclude the persistent-table parameter from url
128+ if (queryString !== false ) {
129+ params_arr = queryString .split (" &" );
130+ for (let i = params_arr .length - 1 ; i >= 0 ; i-- ) {
131+ let param = params_arr[i].split (" =" )[0 ];
132+ if (param === ' persistent-table' ) {
133+ params_arr .splice (i, 1 );
134+ }
135+ }
136+ newUrl = params_arr .length ? tmpUrl + " ?" + params_arr .join (" &" ) : tmpUrl;
137+ }
138+ window .history .pushState ({}, ' ' , newUrl);
139+ localStorage .setItem (' {{ Str:: slug ($crud -> getRoute ()) } } _list_url' , newUrl);
126140 },
127141 dataTableConfiguration: {
128142
@@ -263,6 +277,8 @@ functionsToRunOnDataTablesDrawEvent: [],
263277
264278 window .crud .table = $ (" #crudTable" ).DataTable (window .crud .dataTableConfiguration );
265279
280+ window .crud .updateUrl (location .href );
281+
266282 // move search bar
267283 $ (" #crudTable_filter" ).appendTo ($ (' #datatable_search_stack' ));
268284 $ (" #crudTable_filter input" ).removeClass (' form-control-sm' );
0 commit comments