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

Resetting filters when persistent table is enabled #5738

Open
jargoud opened this issue Dec 16, 2024 · 6 comments
Open

Resetting filters when persistent table is enabled #5738

jargoud opened this issue Dec 16, 2024 · 6 comments
Assignees

Comments

@jargoud
Copy link

jargoud commented Dec 16, 2024

Bug report

What I did:

When persistent table is enabled in configuration (backpack.operations.list.persistentTable = true), after typing terms in the search field, I want to reset the filters to clear the field.

What I expected to happen:

After a click on reset link, the field is cleared.

What happened:

After a click on reset link, the field is not cleared.

What I've already tried to fix it:

The package defines the crud route as follows:

$this->crud->setRoute(backpack_url('user'));

It leads to a local storage key looking like:

httpmy-laravellocalhost8000adminuser_list_url

If I change this into:

CRUD::setRoute(config('backpack.base.route_prefix') . '/user');

The local storage key is now:

adminuser_list_url

and the reset button works.

I am not sure if that issue should be created here or in Backpack core project.

Backpack, Laravel, PHP, DB version:

PHP VERSION:

8.3.14

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, intl, SPL, ldap, mbstring, session, standard, odbc, pcntl, exif, mysqlnd, PDO, pdo_dblib, pdo_mysql, PDO_ODBC, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, pspell, random, readline, Reflection, mysqli, shmop, SimpleXML, soap, sockets, sodium, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, xml, xmlreader, xmlwriter, xsl, zip, rdkafka, imagick, redis, Zend OPcache

LARAVEL VERSION:

11.35.1.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.3.6
backpack/crud: 6.7.43
backpack/generators: v4.0.7
backpack/medialibrary-uploaders: 1.2.1
backpack/permissionmanager: 7.2.1
backpack/pro: 2.2.29
backpack/settings: 3.1.1
backpack/theme-tabler: 1.2.15

Copy link

welcome bot commented Dec 16, 2024

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 mediums:

  • 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;

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, I can address your issue regarding resetting filters when persistent table is enabled. This appears to be a known issue that has been discussed and addressed in Backpack.

The problem you're experiencing with the reset button not clearing the filters when persistent table is enabled is related to how Backpack handles the localStorage keys for persistent tables.

Your workaround of changing the route definition from:

$this->crud->setRoute(backpack_url('user'));

to:

CRUD::setRoute(config('backpack.base.route_prefix') . '/user');

is actually addressing a symptom of the underlying issue, but it's not the recommended solution.

The core of this problem has been addressed in a pull request that fixes datatable persistency when manually filtering. According to the pull request #4558, there were two main issues:

  1. Datatable persistency was not re-applying filters if you manually filtered the table using a custom URL (like http://backpack.com/admin/entity?filter=1).
  2. There was a bug with the persistent attribute that would stick in the URL, causing it to accumulate (e.g., ?persistent-table=true&persistent-table=true).

The pull request implemented a fix by re-implementing the updateUrl script to strip the persistent-table attribute and save only the correct URL.

Given that you're using a recent version of Backpack (6.7.43), this fix should already be included in your installation. If you're still experiencing the issue, it might be worth checking if there are any conflicts with your specific implementation or if there are any newer updates available.

To properly reset the filters and clear the search field, you should be able to use the "Reset" button that comes with Backpack by default. If this button is not visible or not working as expected, you might want to check your CRUD configuration to ensure it's not disabled.

If the issue persists after confirming you have the latest updates and that the reset button is properly configured, I would recommend opening a new issue on the Backpack CRUD GitHub repository with your specific setup and steps to reproduce the problem.

ℹ️ 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] The ListOperation reset button does not work properly when the route is defined by route name (not path)
Github Issue (closed): Filters not cleaning properly
Github Issue (closed): [4.0][BUG] Trying to pre-filter an entity list using url filters does not work if persistency is active.
Github Issue (closed): Return link resets filters
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] Clear Filters doesn't reset 'setModel'
Github Issue (closed): [4.0.7] select2_ajax filter breaks "Remove filters" button
Github Issue (closed): [Bug] Return link resets filters in some case
Github Issue (closed): [Bug] Select2 Filter Does Not Trigger a Change
Github Issue (closed): [4.2][Proposal] Should we remove the Clear Filters button?
Github Issue (closed): [Bug] Persistent datatable filters causes incorrect redirects with multiple projects on subdomains
Github Issue (closed): [4.1][Improvement][Proposal] PersistentTable default duration to 120 minutes + Reset button
fix datatable persistency when manually filtering

@karandatwani92
Copy link
Contributor

karandatwani92 commented Dec 17, 2024

Hey @pxpm

When creating a new CRUD via the command php artisan backpack:crud monster , the CRUD by default comes with the following, and the reset button works fine - it clears the search field and filters.

`CRUD::setRoute(config('backpack.base.route_prefix') . '/monster');`

BUT If I change it to the following, the reset button clears filters, not the search field.

CRUD::setRoute(backpack_url('monster'));

What do you think about this?

@karandatwani92
Copy link
Contributor

Thanks @jargoud for reporting the issue.

@karandatwani92 karandatwani92 added Priority: SHOULD Minor Bug A bug that happens only in a very niche or specific use case. labels Dec 17, 2024
@pxpm
Copy link
Contributor

pxpm commented Dec 18, 2024

The correct way to define routes is admin/something, not https://host.com/admin/something. backpack_url() generates an url, with protocol etc.

I agree that setRoute() could probably set the prefix automatically, I find it cumbersome to have to type it everytime. I am tempted to create setupBackpackRoute('something') method, that would add the prefix automatically without a breaking change.

Or if we plan this for v7 and @tabacitu agrees we can make this setupRoute() add the backpack prefix automatically, keeping it non-bc for users that have setup config().'/something', but a BC for people that don't wan't the prefix and/or have some other prefix behind the backapack one, eg: config('my-prefix').'/'.config('backpack-prefix').'/something'.

I like the flexibility we have now, but I hate to have to type the config prefix part every time.

What do you think @tabacitu ?
1 - do nothing about it.
2 - create the setBackpackRoute() that automatically add the prefix
3 - change the current setRoute() to automatically add the prefix with a BC in some scenarios ?

@pxpm pxpm assigned tabacitu and unassigned pxpm Dec 18, 2024
@pxpm pxpm added enhancement and removed Priority: SHOULD Minor Bug A bug that happens only in a very niche or specific use case. labels Dec 18, 2024
@pxpm pxpm transferred this issue from Laravel-Backpack/PermissionManager Dec 18, 2024
Copy link

Based on the information provided in the knowledge sources, I can address your issue regarding resetting filters when persistent table is enabled. This appears to be a known issue that has been discussed and addressed in Backpack.

The problem you're experiencing with the reset button not clearing the filters when persistent table is enabled is related to how Backpack handles the localStorage keys for persistent tables.

Your workaround of changing the route definition from:

$this->crud->setRoute(backpack_url('user'));

to:

CRUD::setRoute(config('backpack.base.route_prefix') . '/user');

is actually addressing a symptom of the underlying issue, but it's not the recommended solution.

The core of this problem has been addressed in a pull request that fixes datatable persistency when manually filtering. According to the PR #4558, there were two main issues:

  1. Datatable persistency was not re-applying filters if you manually filtered the table using a custom URL (like http://backpack.com/admin/entity?filter=1).
  2. There was a bug with the persistent attribute that would stick in the URL, causing it to accumulate (e.g., ?persistent-table=true&persistent-table=true).

The PR implemented a solution by re-implementing the updateUrl script to strip the persistent-table attribute and save only the correct URL.

Given that you're using a recent version of Backpack (6.7.43), this fix should already be included in your installation. If you're still experiencing the issue, it might be worth checking if there are any conflicts with your specific implementation or if there are any newer updates available.

To properly reset the filters and clear the search field, you should be able to use the "Reset" button that comes with Backpack by default. If this button is not visible or not working as expected, you might want to check your CRUD configuration to ensure it's not disabled.

If the issue persists after confirming you have the latest updates and that the reset button is properly configured, I would recommend opening a new issue on the Backpack CRUD GitHub repository with your specific setup and steps to reproduce the problem.

ℹ️ 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] The ListOperation reset button does not work properly when the route is defined by route name (not path)
Github Issue (closed): Filters not cleaning properly
Github Issue (closed): [4.0][BUG] Trying to pre-filter an entity list using url filters does not work if persistency is active.
Github Issue (closed): Return link resets filters
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] Clear Filters doesn't reset 'setModel'
Github Issue (closed): [4.0.7] select2_ajax filter breaks "Remove filters" button
Github Issue (closed): [Bug] Return link resets filters in some case
Github Issue (closed): [Bug] Select2 Filter Does Not Trigger a Change
Github Issue (closed): [4.2][Proposal] Should we remove the Clear Filters button?
Github Issue (closed): [Bug] Persistent datatable filters causes incorrect redirects with multiple projects on subdomains
Github Issue (closed): [4.1][Improvement][Proposal] PersistentTable default duration to 120 minutes + Reset button
fix datatable persistency when manually filtering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

4 participants