Skip to content

Commit 296484f

Browse files
committed
fix persistence
1 parent 9c61441 commit 296484f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/resources/views/crud/components/datatable/datatable_logic.blade.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,17 @@ functionsToRunOnDataTablesDrawEvent: [],
242242
243243
// Check if saved url has any parameter or is empty after clearing filters
244244
if (savedListUrl && savedListUrl.indexOf('?') >= 1) {
245-
const persistentUrl = savedListUrl + '&persistent-table=true';
246-
247-
const currentUrlHasParams = window.location.href.indexOf('?') >= 1 && window.location.href.split('?')[1] !== '';
248245
const isOurOwnPersistenceRedirect = window.location.search.indexOf('persistent-table=true') >= 1;
246+
const currentUrlHasParams = window.location.search.length > 1;
249247
250-
if (!currentUrlHasParams) {
251-
// No parameters in current URL - redirect to restore persistent state
248+
if (isOurOwnPersistenceRedirect) {
249+
// This is the result of our own redirect, nothing to do
250+
} else if (currentUrlHasParams) {
251+
localStorage.setItem(`${config.persistentTableSlug}_list_url`, window.location.href);
252+
} else {
253+
// No params in current URL — restore the persistent state
254+
const persistentUrl = savedListUrl + '&persistent-table=true';
255+
252256
if (config.persistentTableDuration) {
253257
const savedListUrlTime = localStorage.getItem(`${config.persistentTableSlug}_list_url_time`);
254258
@@ -257,19 +261,14 @@ functionsToRunOnDataTablesDrawEvent: [],
257261
const savedTime = new Date(parseInt(savedListUrlTime));
258262
savedTime.setMinutes(savedTime.getMinutes() + config.persistentTableDuration);
259263
260-
// If the save time is not expired, redirect
261264
if (savedTime > currentDate) {
262265
window.location.href = persistentUrl;
263266
}
264267
}
265268
} else {
266-
// No duration specified, just redirect
267269
window.location.href = persistentUrl;
268270
}
269-
} else if (isOurOwnPersistenceRedirect) {
270-
// This is our own persistence redirect looping back, do nothing
271271
}
272-
// else: URL already has params the user explicitly navigated to — do not override them
273272
}
274273
}
275274

0 commit comments

Comments
 (0)