Hi,
Would you have some tips and advices about how to let a visitor sorting items by prices with a button, for exemple from lower to higher.
Actuallly, products are diplayed in a products page with pagination, and use some categories and tags.
I thought about a JS solution, but I’m sur it’s not the best way specially with a pagination.
Thank you
Thanks Texnixe, I was trying something like this:
controller:
$items = $page->children()->listed()->sortBy('order', 'asc');
if(r::is('POST')) {
$items = $page->children()->listed()->sortBy('price', 'asc');
};
witch works pretty fine, but does not keep sort order under pagination pages
Yes, it’s better to work with GET request and check for a sort parameter instead of a POST request. That way your pagination will stay intact. If you use a POST request, it get’s more ccomplicated, because you have to store your value in the session to make it available across different pages.
The easiest way is to use a GET request instead of a POST by changing the method in your form and removing the check for POST request in your controller. There is absolutely no reason to send a POST request for this filtering stuff.
If you want to keep the POST request for some reason, you would have to perpetuate your filter data in a session cookie.
This works completely without Ajax or any other JavaScript.
1 Like
It works perfectly with GET, Thank you.