Following a few tutorials, I have set up a page that contains a list of movies on my site and a few filters in the left sidebar. I would like to add a div that displays all the active filters -something like this https://www.screencast.com/t/302RMBdxGHHR
While this works, it is a very quick and dirty solution because what I am doing there is the following:
- I am taking the selected filters from an array in my movie.php >> I think that is fine
- In the Twig section of the 'active filter' partial, I am adding a remove-icon with a class like 'genre-remove' >> I think/hope that is fine too.
- JQuery is listening to a click-event on this class name, then -here it comes- sets the checked-property of the corresponding checkbox in the filter to false and finally does a form request again >> This annoys me terribly.
This feels very much the work of an amateur to me, and I was wondering what the recommended practice is to accomplish this. Does anyone have any suggestions? Thanks in advance!
You perform an ajax call any times to check/uncheck genre filter? Yeah that's heavy.
What I would do is add a class to each movie card (title/description) which corresponds to the genre of the movie. When a filter is checked, any other cards filter is hidden.
The problem comes with the pagination: if you have 500 movies and display them by chunks of 20 per page: add a filter "Action" should display 20 action movies but it will only display the action movies of the initial chunks, maybe 0 if none was present in the chunk. Am I clear?
What I would do to prevent this is to modify the query to ensure I have at least 20 movies of any genre (or all of the movies of the genre if I only have few).
Doing that way for sure you are performing a "huge" request at the loading of the page, but you are doing only one request, and one sql request is fast compared to many AJAX loads.
This is what I would do, maybe not the perfect way. Hope this helps :)
I understand your suggestion to add classes, the problem that is introduced by doing so, and the solution you are suggesting. I think it may fall short, however, as you indeed have to start implementing extra code to cover specific 'page&sorting'-scenarios.
Truth is, I do not mind the ajax calls -in fact, I have implemented ajax facet filters on quite a few drupal sites, and it works just fine. Yes, my dev October could be faster, but I am fairly confident that has got everything to do with my local dev environment (virtual machine with a Vagrant Scotchbox) and not so much with the ajax calls, which I think I will keep.
Regardless, thanks for your answer -I really do appreciate it that you took the time to answer and to suggest something! :)
1-3 of 3