Sorting Custom Module on click function

Hi,
Help required
How can I sort ASC or DESC of custom module listing when we click two buttons. Any option to pass param to the url or any other options?

Regards
Manoj Gregory

Hi Manoj,

It really depends on how your data is layed out.

If you are using data in a table type layout, I would use a plugin like this: https://datatables.net/
and configure it how you need.

If I was doing complex listing layouts ie like a shop… i would use something like this.
https://rtwebdocs.treepl.co/url-param-sorting?sort=asc

I have just very quickly done this up now as a demo. You can use the code as you wish and adjust accoridingly.

Now this is just using liquid - in particular a case to read the url param , assign a variable accordingly and then dump that variable in the component call.

I use a case to account for user entering unaccounted for url parameters. There is probably many different ways to skin this cat. This would be just one way that I would approach it.

Code is on that page above if you would like to use it :slight_smile:

4 Likes

Hi James,

Great help thank you so much.

Regards
Manoj Gregory

Hey James, I also love those other code snippets you have on that page you linked. Hope you don’t mind me trying out some of them :-).

Hi @TimL Go for it! some of them are just me testing out ideas.
Let me know if you need the liquid code for anything there :slight_smile:

1 Like

@James very nice. Went looking around and it looks like you’ve got yourself a nice collection of code snippets ther :slight_smile:

Very nice collection @James :muscle::+1:
I know some of them are on the Treehouse site, but I think there are some of them that would be great to add there as well :slight_smile: