Sorting collections with buttons

Hello!
I’m looking for a simple way to update the sorting of a collection (like a feed of blog articles) with buttons. Like, if the table starts as date asc, but on button click it is sorted as title asc.

I’ve been looking for more documentation but not finding much.
I see https://listjs.com/ may be an option, but am wondering if Kirby has anything built in.

Also curious to find a working list.js x kirby cms example to study.

Do you mean in your frontend? Kirby does not come with any JavaScript for the frontend, this is totally up to you.

Yes, I mean to show on the site for visitors to organize a list of posts.
Is there a plugin maybe? Or is there a Kirby function with php?
Thanks

In general there are multiple ways to go about this, and nothing Kirby specific is required here, nor a plugin

  • your button submits a form with a get request to the backend, depending on the value you change the order of the sorting
  • you do it purely client side with for example list.js with no backend stuff at all
  • if you don’t want a frontend reload which you would get with option a, you can send a request to the backend via Ajax

Okay, good to know. How would I pull data from the backend of Kirby?
Would it be just a PHP function with the first point you mentioned? Just trying to figure out what to google haha. Let me know if you might be able to point me to other resources. Thanks for your help.

Your button could just be a link as well, then you could do it like described here: Filtering with tags | Kirby CMS, with the only difference that you would not filter but sort

A form submit button would work similar to the search described here: Search | Kirby CMS, again with the difference that you would not return the search results but a resorted collection.

Thank you! I will look into these.

When filtering with PHP buttons, the array it’s calling from will correspond with Kirby content, right? Like, I wont need to use SQL? Thanks!

Yes, you don’t need a database for that. You can use Kirby’s filter methods for collections.