How to sort a table through a dropdown menu

So I have 2 issues that I’m trying to figure out:
First what do I need to code to have my table sorted via a drop down menu.
for example, user selects Name (AtoZ) and it sorts by ascending, or selects Rating(Ascending) etc.

Second, In my database, I have a referenced field and it looks like I am unable to sort by referenced fields. What are some solutions?

Thanks for all your help

Wix reference fields have to be filtered by your dataset settings.
https://support.wix.com/en/article/field-type-support-and-limitations-in-the-data-manager
https://support.wix.com/en/article/about-reference-fields-in-database-collections

As for the filtering of table, then see here.
https://support.wix.com/en/article/filtering-content-based-on-user-selection
https://www.wix.com/corvid/forum/corvid-tips-and-updates/how-to-create-a-search-for-your-database

@givemeawhisky
Thanks for this information I will look into this when I have time but from a quick glance, This gives a lot of information how to filter my dataset. I currently have a working search bar for my table that filters information, but I was hoping to actually sort my information by various different orders, Ascending, Descending, etc.