Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Persisting sorting, ordering, and visibility is broken after a recent update #5762

Open
fawzanm opened this issue Jan 30, 2025 · 3 comments · May be fixed by #5765
Open

[Bug] Persisting sorting, ordering, and visibility is broken after a recent update #5762

fawzanm opened this issue Jan 30, 2025 · 3 comments · May be fixed by #5765
Assignees

Comments

@fawzanm
Copy link

fawzanm commented Jan 30, 2025

Bug report

What I did

Used the persistentTable feature in Backpack CRUD to maintain table state (page length, search, sort, visibility etc.) across page refreshes. The issue manifests when checking the cached table information against available page lengths.

 'pageLengthMenu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'backpack::crud.all']],

What I expected to happen

The persistentTable feature should maintain the table state correctly across page refreshes, storing and retrieving the correct page length settings from localStorage.

What happened

The table state is being incorrectly cleared from localStorage due to a faulty comparison in the new code block introduced in version 6.5.47

9d1c5a6

What I've already tried to fix it

the below code block causes the issue in datatables_logic.blade.php.

if($dtCachedInfo.length !== 0 && $pageLength.indexOf($dtCachedInfo.length) === -1) {
    localStorage.removeItem('DataTables_crudTable_/{{$crud->getRoute()}}');
}

If we change it with the below snippet. It works

if($dtCachedInfo.length !== 0 && $pageLength[0].indexOf($dtCachedInfo.length) === -1) {
    localStorage.removeItem('DataTables_crudTable_/{{$crud->getRoute()}}');
}

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there?

Yes

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

8.3.16

PHP EXTENSIONS:

Core, date, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dba, dom, hash, FFI, fileinfo, filter, ftp, gd, gettext, gmp, json, iconv, SPL, session, standard, mbstring, igbinary, imagick, imap, intl, ldap, exif, mongodb, mysqlnd, mysqli, pcntl, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, random, readline, redis, Reflection, shmop, SimpleXML, soap, sockets, sodium, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlreader, xmlwriter, xsl, zip, zstd, herd, Zend OPcache

LARAVEL VERSION:

11.41.0.0

BACKPACK PACKAGE VERSIONS:

backpack/activity-log: 2.0.6
backpack/backupmanager: v5.0.5
backpack/basset: 1.3.6
backpack/crud: 6.7.50
backpack/editable-columns: 3.0.11
backpack/filemanager: 3.0.10
backpack/generators: v4.0.7
backpack/logmanager: v5.0.2
backpack/pagemanager: 3.3.2
backpack/permissionmanager: 7.2.1
backpack/pro: 2.2.32
backpack/settings: 3.1.1
backpack/theme-tabler: 1.2.17

@fawzanm fawzanm added the triage label Jan 30, 2025
Copy link

welcome bot commented Jan 30, 2025

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use GitHub Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - GitHub Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

Copy link

Based on the information provided in the knowledge sources and the user's question, I can address this issue related to Backpack's persistentTable feature.

The user is experiencing a bug with the persistentTable feature in Backpack CRUD, which is supposed to maintain table state (page length, search, etc.) across page refreshes. The issue appears to be related to a recent update, specifically version 6.5.47.

The problem stems from a code block in the datatables_logic.blade.php file:

if($dtCachedInfo.length !== 0 && $pageLength.indexOf($dtCachedInfo.length) === -1) {
    localStorage.removeItem('DataTables_crudTable_/{{$crud->getRoute()}}');
}

This code is incorrectly clearing the table state from localStorage due to a faulty comparison.

The user has found a solution by modifying the code to:

if($dtCachedInfo.length !== 0 && $pageLength[0].indexOf($dtCachedInfo.length) === -1) {
    localStorage.removeItem('DataTables_crudTable_/{{$crud->getRoute()}}');
}

This issue is similar to problems reported in previous versions of Backpack, where persistent table settings were not working correctly. For example, in Github Issue #3545, there was a problem with entries per page not being remembered correctly.

To address this issue, you can try the following:

  1. Implement the user's suggested fix by modifying the datatables_logic.blade.php file as shown above.

  2. Clear your browser's cache and local storage to ensure you're not using any outdated settings.

  3. If the issue persists, you may want to check if there are any conflicts with other JavaScript code or Backpack settings that could be interfering with the persistentTable functionality.

  4. Consider reporting this issue to the Backpack GitHub repository, as it appears to be a bug introduced in a recent update.

If these steps don't resolve the issue, you may need to wait for an official fix from the Backpack team. Keep an eye on the Backpack CRUD GitHub repository for updates or potential fixes related to this issue.

ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️

Relevant sources:

Github Issue (closed): [Bug] Entries per page are not remembered (persistent table - true)
Github Issue (closed): [Bug] The ListOperation reset button does not work properly when the route is defined by route name (not path)
Github Issue (closed): [Bug] Wrong handling of localstorage key name when resetting datatable if resetButtons is true but home_link is empty
Github Issue (closed): [Bug] Persistent datatable filters causes incorrect redirects with multiple projects on subdomains
Github Issue (closed): Setting default page length does nothing.
Datatables Persistent URL Tracking Fix
Github Issue (closed): [Bug] Test adding new issues automatically to the This Week project
Changed localstorage key for the List View persistance
Github Issue (closed): [Bug] Upgrade BackPack v5 to v6
Github Issue (closed): [Bug] Search is not working correctly
Github Issue (closed): [4.0][Bug] setPersistentTable not working
Github Issue (closed): [Bug] persistenTable doesn't seem to work with bulk actions
fix datatable persistency when manually filtering
fix datatables reseting page length
Github Issue (closed): Persistent table : wrong redirection in case of multiple CRUD for same entity

@karandatwani92
Copy link
Contributor

Hey @fawzanm

Thanks for reporting the issue.

@pxpm I tested it and found that persistent is currently working only for:

  • filters ✅
  • page length ❌
  • Search ❌
  • Sort ❌
  • visibility ❌

@pxpm pxpm linked a pull request Jan 31, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants