From 9d1c5a620488feb0a479576cba3a116ceb6e64bf Mon Sep 17 00:00:00 2001 From: pxpm Date: Wed, 8 Jan 2025 15:30:59 +0000 Subject: [PATCH] fix page lenght stalling in cache --- src/app/Http/Controllers/Operations/ListOperation.php | 3 ++- .../views/crud/inc/datatables_logic.blade.php | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/app/Http/Controllers/Operations/ListOperation.php b/src/app/Http/Controllers/Operations/ListOperation.php index f9ea830507..ed20569299 100644 --- a/src/app/Http/Controllers/Operations/ListOperation.php +++ b/src/app/Http/Controllers/Operations/ListOperation.php @@ -110,7 +110,8 @@ public function search() $filteredEntryCount = $this->crud->getFilteredQueryCount() ?? $totalEntryCount; } else { $totalEntryCount = $length; - $filteredEntryCount = $entries->count() < $length ? 0 : $length + $start + 1; + $entryCount = $entries->count(); + $filteredEntryCount = $entryCount < $length ? $entryCount : $length + $start + 1; } // store the totalEntryCount in CrudPanel so that multiple blade files can access it diff --git a/src/resources/views/crud/inc/datatables_logic.blade.php b/src/resources/views/crud/inc/datatables_logic.blade.php index 6610fc6c60..c34020b7d6 100644 --- a/src/resources/views/crud/inc/datatables_logic.blade.php +++ b/src/resources/views/crud/inc/datatables_logic.blade.php @@ -23,12 +23,19 @@ let $dtCachedInfo = JSON.parse(localStorage.getItem('DataTables_crudTable_/{{$crud->getRoute()}}')) ? JSON.parse(localStorage.getItem('DataTables_crudTable_/{{$crud->getRoute()}}')) : []; var $dtDefaultPageLength = {{ $crud->getDefaultPageLength() }}; - let $dtStoredPageLength = localStorage.getItem('DataTables_crudTable_/{{$crud->getRoute()}}_pageLength'); + let $pageLength = @json($crud->getPageLengthMenu()); + + let $dtStoredPageLength = parseInt(localStorage.getItem('DataTables_crudTable_/{{$crud->getRoute()}}_pageLength')); if(!$dtStoredPageLength && $dtCachedInfo.length !== 0 && $dtCachedInfo.length !== $dtDefaultPageLength) { localStorage.removeItem('DataTables_crudTable_/{{$crud->getRoute()}}'); } + if($dtCachedInfo.length !== 0 && $pageLength.indexOf($dtCachedInfo.length) === -1) { + localStorage.removeItem('DataTables_crudTable_/{{$crud->getRoute()}}'); + } + + // in this page we always pass the alerts to localStorage because we can be redirected with // persistent table, and this way we guarantee non-duplicate alerts. $oldAlerts = JSON.parse(localStorage.getItem('backpack_alerts')) @@ -226,7 +233,7 @@ functionsToRunOnDataTablesDrawEvent: [], @endif autoWidth: false, pageLength: $dtDefaultPageLength, - lengthMenu: @json($crud->getPageLengthMenu()), + lengthMenu: $pageLength, /* Disable initial sort */ aaSorting: [], language: {