20
20
// datatables caches the ajax responses with pageLength in LocalStorage so when changing this
21
21
// settings in controller users get unexpected results. To avoid that we will reset
22
22
// the table cache when both lengths don't match.
23
- let $dtCachedInfo = JSON .parse (localStorage .getItem (' DataTables_crudTable_/{{ $crud -> getRoute ( )} }' ))
24
- ? JSON .parse (localStorage .getItem (' DataTables_crudTable_/{{ $crud -> getRoute ( )} }' )) : [];
23
+ let $dtCachedInfo = JSON .parse (localStorage .getItem (' DataTables_crudTable_/{{ $crud -> getOperationSetting ( " datatablesUrl " )} }' ))
24
+ ? JSON .parse (localStorage .getItem (' DataTables_crudTable_/{{ $crud -> getOperationSetting ( " datatablesUrl " )} }' )) : [];
25
25
var $dtDefaultPageLength = {{ $crud -> getDefaultPageLength () } } ;
26
- let $dtStoredPageLength = localStorage .getItem (' DataTables_crudTable_/{{ $crud -> getRoute ( )} } _pageLength' );
26
+ let $dtStoredPageLength = localStorage .getItem (' DataTables_crudTable_/{{ $crud -> getOperationSetting ( " datatablesUrl " )} } _pageLength' );
27
27
28
28
if (! $dtStoredPageLength && $dtCachedInfo .length !== 0 && $dtCachedInfo .length !== $dtDefaultPageLength) {
29
- localStorage .removeItem (' DataTables_crudTable_/{{ $crud -> getRoute ( )} }' );
29
+ localStorage .removeItem (' DataTables_crudTable_/{{ $crud -> getOperationSetting ( " datatablesUrl " )} }' );
30
30
}
31
31
32
32
// in this page we always pass the alerts to localStorage because we can be redirected with
51
51
52
52
@if ($crud -> getPersistentTable () )
53
53
54
- var saved_list_url = localStorage .getItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url' );
54
+ var saved_list_url = localStorage .getItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url' );
55
55
56
56
// check if saved url has any parameter or is empty after clearing filters.
57
57
if (saved_list_url && saved_list_url .indexOf (' ?' ) < 1 ) {
71
71
}
72
72
73
73
@if ($crud -> getPersistentTableDuration () )
74
- var saved_list_url_time = localStorage .getItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url_time' );
74
+ var saved_list_url_time = localStorage .getItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url_time' );
75
75
76
76
if (saved_list_url_time) {
77
77
var $current_date = new Date ();
@@ -118,7 +118,7 @@ functionsToRunOnDataTablesDrawEvent: [],
118
118
fn .apply (window , args);
119
119
},
120
120
updateUrl : function (url ) {
121
- let urlStart = " {{ url ($crud -> route ) } }" ;
121
+ let urlStart = " {{ url ($crud -> getOperationSetting ( " datatablesUrl " ) ) } }" ;
122
122
let urlEnd = url .replace (urlStart, ' ' );
123
123
urlEnd = urlEnd .replace (' /search' , ' ' );
124
124
let newUrl = urlStart + urlEnd;
@@ -139,7 +139,7 @@ functionsToRunOnDataTablesDrawEvent: [],
139
139
}
140
140
window .history .pushState ({}, ' ' , newUrl);
141
141
@if ($crud -> getPersistentTable () )
142
- localStorage .setItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url' , newUrl);
142
+ localStorage .setItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url' , newUrl);
143
143
@endif
144
144
},
145
145
dataTableConfiguration: {
@@ -195,7 +195,7 @@ functionsToRunOnDataTablesDrawEvent: [],
195
195
196
196
stateSaveParams : function (settings , data ) {
197
197
198
- localStorage .setItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url_time' , data .time );
198
+ localStorage .setItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url_time' , data .time );
199
199
200
200
data .columns .forEach (function (item , index ) {
201
201
var columnHeading = crud .table .columns ().header ()[index];
@@ -213,11 +213,11 @@ functionsToRunOnDataTablesDrawEvent: [],
213
213
214
214
// if the save time as expired we force datatabled to clear localStorage
215
215
if ($saved_time < $current_date) {
216
- if (localStorage .getItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url' )) {
217
- localStorage .removeItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url' );
216
+ if (localStorage .getItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url' )) {
217
+ localStorage .removeItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url' );
218
218
}
219
- if (localStorage .getItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url_time' )) {
220
- localStorage .removeItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url_time' );
219
+ if (localStorage .getItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url_time' )) {
220
+ localStorage .removeItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url_time' );
221
221
}
222
222
return false ;
223
223
}
@@ -269,7 +269,7 @@ functionsToRunOnDataTablesDrawEvent: [],
269
269
@endif
270
270
searching: @json ($crud -> getOperationSetting (' searchableTable' ) ?? true ),
271
271
ajax: {
272
- " url" : " {!! url ($crud -> route . ' /search' ). ' ?' . Request:: getQueryString () ! !}" ,
272
+ " url" : " {!! url ($crud -> getOperationSetting ( " datatablesUrl " ) . ' /search' ). ' ?' . Request:: getQueryString () ! !}" ,
273
273
" type" : " POST" ,
274
274
" data" : {
275
275
" totalEntryCount" : " {{ $crud -> getOperationSetting (' totalEntryCount' ) ?? false } }"
@@ -312,24 +312,24 @@ functionsToRunOnDataTablesDrawEvent: [],
312
312
313
313
@if ($crud -> getOperationSetting (' resetButton' ) ?? true )
314
314
// create the reset button
315
- var crudTableResetButton = ' <a href="{{ url ($crud -> route )} } " class="ml-1 ms-1" id="crudTable_reset_button">{{ trans (' backpack::crud.reset' ) } } </a>' ;
315
+ var crudTableResetButton = ' <a href="{{ url ($crud -> getOperationSetting ( " datatablesUrl " ) )} } " class="ml-1 ms-1" id="crudTable_reset_button">{{ trans (' backpack::crud.reset' ) } } </a>' ;
316
316
317
317
$ (' #datatable_info_stack' ).append (crudTableResetButton);
318
318
319
319
// when clicking in reset button we clear the localStorage for datatables.
320
320
$ (' #crudTable_reset_button' ).on (' click' , function () {
321
321
322
322
// clear the filters
323
- if (localStorage .getItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url' )) {
324
- localStorage .removeItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url' );
323
+ if (localStorage .getItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url' )) {
324
+ localStorage .removeItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url' );
325
325
}
326
- if (localStorage .getItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url_time' )) {
327
- localStorage .removeItem (' {{ Str:: slug ($crud -> getRoute ( )) } } _list_url_time' );
326
+ if (localStorage .getItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url_time' )) {
327
+ localStorage .removeItem (' {{ Str:: slug ($crud -> getOperationSetting ( " datatablesUrl " )) } } _list_url_time' );
328
328
}
329
329
330
330
// clear the table sorting/ordering/visibility
331
- if (localStorage .getItem (' DataTables_crudTable_/{{ $crud -> getRoute ( ) } }' )) {
332
- localStorage .removeItem (' DataTables_crudTable_/{{ $crud -> getRoute ( ) } }' );
331
+ if (localStorage .getItem (' DataTables_crudTable_/{{ $crud -> getOperationSetting ( " datatablesUrl " ) } }' )) {
332
+ localStorage .removeItem (' DataTables_crudTable_/{{ $crud -> getOperationSetting ( " datatablesUrl " ) } }' );
333
333
}
334
334
});
335
335
@endif
@@ -350,7 +350,7 @@ functionsToRunOnDataTablesDrawEvent: [],
350
350
// so in next requests we know if the length changed by user
351
351
// or by developer in the controller.
352
352
$ (' #crudTable' ).on ( ' length.dt' , function ( e , settings , len ) {
353
- localStorage .setItem (' DataTables_crudTable_/{{ $crud -> getRoute ( )} } _pageLength' , len);
353
+ localStorage .setItem (' DataTables_crudTable_/{{ $crud -> getOperationSetting ( " datatablesUrl " )} } _pageLength' , len);
354
354
});
355
355
356
356
$ (' #crudTable' ).on ( ' page.dt' , function () {
0 commit comments