Filtering dataset via code empties dataset. Please Help,

I have a dataset #dataset5 which is connected to a collection of which one of the categories is “Name”.
I am trying to filter the dataset based on the value of a dropdown list.
When the page loads, the repeater connected to the dataset populates as expected.
When the user makes a choice from the drop down, the repeater disappears… which to me suggests that the dataset is empty, although I know it shouldn’t be.

Here is the code in question:


function filter(){
 let newFilter = wixData.filter();
    newFilter = newFilter.contains("Name", "Tree");
    $w('#dataset5').setFilter(newFilter);
}

export function plantType_change(event) {
    filter();
}

I used “Tree” in the third line to remove the possibility of the error coming from my use of the dropdown value.

Here is a screenshot of the table to show that the filtered dataset should not be empty:

In addition I have tried changing the filter type from “contains()” to “isNotEmpty( )” . Same deal.

Would love some help here.

Thanks;

@allon-schamroth Corvid only cares about the field key and not the field name that you see displayed in the column heading called “Name”. Be sure the actual field key is “Name” and not “name”.

Also, it looks like you are filtering on the literal value “Tree”. Perhaps you are only doing that while testing. In any event, you will need to eventually be using the dropdown value, something like this:

function filter(event){
 let newFilter = wixData.filter();
    newFilter = newFilter.contains("Name", event.target.value);
    $w('#dataset5').setFilter(newFilter);
}

export function plantType_change(event) {
    filter(event);
}

Thank you so much. That did it. And yes “Tree” was just for testing.

thank you again :slight_smile: