Changing filter in a dataset

Hi, I am interested in how Andreas has managed to change filters in a dataset. Currently, I’ve simply connected the dataset and used the Region field with a Highveld filter, then sorted it with the Plant Category field. But, I’d like users to, for example, click a Small Trees button to bring up a gallery of small Highveld trees. How would I add code that?

Hi, you can use the setFilter API of the dataset.

Thanks. Perhaps now would be a good time to mention that I have no knowledge of javascript so that unfortunately does not help me.

Did you try looking at the code example?

Yes, Tomer, I tried. Unfortunately, when you have no working relationship with javascript, all is as clear as mud. I’ll see if I can find someone else to help me.

Good luck! We’re here to help if you have any further questions, or would like to approach it yourself.

i’m in the same boat tomer , have you found an answer ?

Francisco, can you elaborate on what are you trying to achieve? I will do my best to give you a relevant code sample.

i have a publicly displayed database (PostGiveaways) on my website called #table1 , i would like to make a sort by button, EX sort by host, end date (ending soon)


I need it there above my list , or the Column names themselves would be nice if i could click them if that makes it easy , just anything to help my viewers sort the list .

Here’s what you need to do, I’ll give an example for one button, but you can apply it to more sort buttons:

  1. Add a button, name it “btnSortByX”, for example “btnSortByHost”
  2. Add a click event for the button from the properties panel
  3. Assuming the “Host” field in your collection has the field key “host” (see screenshot below), write the following code inside the click event handler:
$w("#myDataset").setSort(wixData.sort().ascending('host'));

Few notes regarding the code:

  1. In my code the dataset ID is “myDataset”, you need to change it according to your dataset ID.
  2. We use “wix-data” API in order to use the sort functionality, so you need to import “wix-data”.
    This is the entire code:
import wixData from "wix-data";

export function btnSortByHost_click() {
	$w("#myDataset").setSort(wixData.sort().ascending('host'));
}

Getting the field key:

  1. Go to the content manager
  2. Hover over the desired column and click the 3 dot menu button
  3. Click on “Manage properties”
  4. Get the field key:

this is embarissing i know you took your time on that but somethings not getting through to me XD

You have one tiny mistake - the sorting is done on the dataset that feeds the table, not on the table itself.
So you should change in the code “#table1” to your dataset ID

so just change it to (“#PostGiveaways”) ? then it says not a valid selector name

" PostGiveaways " is the name of your collection, not the dataset.
How does the table get data from the collection? Do you feed the data through code, or is the table connected to a dataset?

OMG i got it to work with your help , thank you for being patient with me XD

No problem, glad that it works for you :slight_smile: