Reload page and clear/reset filters

Hi, I have a dynamic category page for a dataset with data displayed in a repeater. Users are able to filter the data displayed using multiple drop downs. I need a ‘clear filters’ button, or even just a button that will reload the whole page - but I can’t for the life of me work out how to do this.

I’ve tried wixLocation.to(url) - with no luck, the page goes back to the top as if it’s refreshing, but the dataset and filters don’t reset.

I’ve tried $w(“#dataset”).refresh() - this doesn’t seem to do anything at all

I’ve tried to reset each dropdown box to 0 i.e. $w(“#dropdown1”).selectedIndex = 0; - this resets the placeholder text in the dropdown to the first option, but the repeater remains filtered.

I’ve also tried just linking the button to the page url - but this still doesn’t refresh the filters??

When I manually refresh the page (i.e. command+r), the page AND the filters refresh. How can I get a button to perform this function?

Thanks in advance :slight_smile:

You can reset the filter using the code shown here in ‘Clear a dataset’s filters’ example
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFilter

A basic reset code example below using valid calls in your code.
https://www.wix.com/corvid/reference/$w.ValidatableMixin.html

THE ELEMENTS

The Page
User Inputs:
First Name Field: #input1
Last Name Field: #input2
Email Field: #input3
Phone Field: #input4
​
Button Element:
Submit Button: #Submit
Reset Button: #Reset


The Database
Create a database Courses (dataset1).
Recommended fields:
First Name ID: fname
Last Name ID: lname
Email ID: email
Phone ID: phone
Course Type ID: course
Course Date ID: date
Course Timing ID: time
Email ID: email
Page Code
// Reset Button //
​
export function Reset_click(event, $w) {
    $w('#input1').value = "";
    $w('#input2').value = "";
    $w('#input3').value = "";
    $w('#input4').value = "";
    $w('#dropdown1').value = "Select Course";
    $w('#dropdown2').value = "Select Timing";

// Reset validation - Otherwise fields will show error //
    $w('#input1').resetValidityIndication();
    $w('#input2').resetValidityIndication();
    $w('#input3').resetValidityIndication();
    $w('#input4').resetValidityIndication();
    $w('#dropdown1').resetValidityIndication();
    $w('#dropdown2').resetValidityIndication();
}

This worked perfectly! Thanks so much :slight_smile:

Hi GOS, I used your code above for my Clear Filters button. While it clears the filters as desired, the repeater items do not reset. Is there an additional bit of code that can be added to make this happen? Thanks :slight_smile:

So I just did a bit more Googling and found a solution - figured I should post here in case it is useful for others.

Note you will need to set the onClick event for your clear filter button ID, rename the dropdowns with your dropdown IDs (and add more/delete depending on the number of dropdowns you have), and rename the dataset with your dataset ID.

// Reset Button //
export function clearButton_click(event, $w) {
    $w("#dropdown1").selectedIndex = 0;
    $w("#dropdown2").selectedIndex = 0;
    $w("#dropdown3").selectedIndex = 0;
    $w("#dataset1").setFilter(wixData.filter());
}

So I have 2 dropdown boxes that filter a repeater and just added a ‘View All’ button to refresh the filters & show all the repeater items. The above code worked and reset the filters and it shows all the repeater items, but when you go to use the dropdown filters again, it won’t filter the repeater anymore. Is there a way to get the dropdown filters to work again after the ‘View All’ button is pushed?

Here’s my current code:

export function button14_click ( event ) {
$w ( ‘#dataset1’ ). setFilter ( wixData . filter ());
$w ( ‘#dropdown4’ ). value = “Specialty” ;
$w ( ‘#dropdown5’ ). value = “State” ;

$w ( '#dropdown4' ). resetValidityIndication (); 
$w ( '#dropdown5' ). resetValidityIndication (); 

}