How to use AJAX in kirby3

Hello.

I have a similar question and didn’t want to open new topic so I reckon I do it here.

On my home page (home.php) I am displaying some products.
I am after the sorting functionality without page reload.
Assuming I have several fields in product blueprint, Filed A, B and C with values I want to use to sort the products.

My question is do I need the content representation for each sortBy and how should that be structured?

Thank you in advance.

I wonder if it is even worth while to send an Ajax request instead of just doing the sorting on the frontend?

Exactly.
But can I have those three sorting options without page reload?

If you do it client side (JavaScript solution), there will be no reload.

1 Like

Do you have any reference that I can take a look at?
Thank you.

Google Javascript sorting libraries, if you don’t want to code it yourself.

Basically, you would listen to click events on the buttons. Then sort your (list) items based on data attributes you add to these items in your PHP.

1 Like