Reset table data, can't filter again

Hi, I use the code below to reset my table’s data and it works great:

export function button5_click(event) {
      $w("#dataset1").setFilter( wixData.filter() );
      $w('#dropdown2').value = "Select something";
      $w('#dropdown2').resetValidityIndication();
 }

The filters in the dropdown menus are set via Editor (Add filter) and not code. So my problem is that after I reset everything (data and dropdown values) as it is seen above, I can’t filter again. My dropdown menus stop filtering. Any ideas please?

Why not coding all the filtering-steps by himself?

Anyway, try this one…

export function button5_click(event) {
      $w("#dataset1").setFilter( wixData.filter() );
      $w('#dropdown2').value = undefined;
      $w('#dropdown2').resetValidityIndication();
 }

Here you will find a similar topic to your problem.
https://www.media-junkie.com/pflegeservice

I would recommend you not to use to much of Wix predefined options.
They all have limits.

Hi there,
My problem was not with the .value or .resetValidityIndication. It’s with the filtering. It clears the filters and then it’s like keeping them cleared for ever. So your code I’m afraid does not work.

But the example in your site is exactly what I’m doing. I only hoped to do something quickly since I’m in such a tight schedule to hard-code…

Thanksa again my friend.

@gemats
If you want to do it quickly, copy and paste the given CODE in the example.
Modify it to your own dropdowns.
That should’t take more than 15-20minutes and you have a working FILTER-ENGINE.

Delete everything what you do not need from the given code and connect a dataset to your Datacollection.

P.S.: Use the (build in code) USER-INTERFACE.

Just put in here all the user-data into the user-interface…
And modify all the IDs of elements (buttons / dropdowns and so on…)


import wixData from 'wix-data';
import {local} from 'wix-storage';
 
//------------- USER-INTERFACE ------------------- User-Interface-------------
var DATABASE    = "HERE_your_DATA_Collection_Name"
var DBlimit     = "Here_the_Database_LimitNumber"
var DATASET     = "HERE_your_Dataset_Name"
//---------------------------------------
var REFERENCE1  = "HereIdReferencefield1" //-> replace RF1 with your Referencefield-id-1
var REFERENCE2  = "HereIdReferencefield2" //-> replace RF2 with your Referencefield-id-2
var REFERENCE3  = "HereIdReferencefield3" //-> and so on....... 
var REFERENCE4  = "HereIdReferencefield4" 
var REFERENCE5  = "HereIdReferencefield5" 
var REFERENCE6  = "HereIdReferencefield6" 
var REFERENCE7  = "HereIdReferencefield7" 
//-----USER-INTERFACE ----------- User-Interface-------------------------------
 
$w.onReady(function () {
    wixData.query(DATABSE)
    .limit(DBlimit)
    .find()
    .then(results => {
        const uniqueTitles1 = getUniqueTitles1(results.items);
        const uniqueTitles2 = getUniqueTitles2(results.items);
        const uniqueTitles3 = getUniqueTitles3(results.items);
        const uniqueTitles4 = getUniqueTitles4(results.items);
 
        $w("#DD1").options = buildOptions1(uniqueTitles1);  //---> STATUS
        $w("#DD2").options = buildOptions2(uniqueTitles2);  //---> ANREDE
        $w("#DD3").options = buildOptions3(uniqueTitles3);  //---> NATIONALITÄT
        $w("#DD4").options = buildOptions4(uniqueTitles4);  //---> VERFÜGBARKEIT
    });
 
    function getUniqueTitles1(items) {const titlesOnly = items.map(item => item.RF1);        return [...new Set(titlesOnly)];}
    function buildOptions1(uniqueList1) {return uniqueList1.map(curr => {return {label:curr, value:curr};});}
 
    function getUniqueTitles2(items) {const titlesOnly = items.map(item => item.RF2);      return [...new Set(titlesOnly)];}
    function buildOptions2(uniqueList2) {return uniqueList2.map(curr => {return {label:curr, value:curr};});}
 
    function getUniqueTitles3(items) {const titlesOnly = items.map(item => item.RF3);   return [...new Set(titlesOnly)];}
    function buildOptions3(uniqueList3) {return uniqueList3.map(curr => {return {label:curr, value:curr};});}
 
    function getUniqueTitles4(items) {const titlesOnly = items.map(item => item.RF4); return [...new Set(titlesOnly)];}
    function buildOptions4(uniqueList4) {return uniqueList4.map(curr => {return {label:curr, value:curr};});}
 
    function getUniqueTitles5(items) {const titlesOnly = items.map(item => item.RF5);    return [...new Set(titlesOnly)];}
    function buildOptions5(uniqueList5) {return uniqueList5.map(curr => {return {label:curr, value:curr};});}
//and so on..........
})

 
//DD1-DD5 = DropDowns------------------------------------------------------
export function DD1_change(event)   {SEARCH_ENGINE();}
export function DD2_change(event)   {SEARCH_ENGINE();}
export function DD3_change(event)   {SEARCH_ENGINE();}
export function DD4_change(event)   {SEARCH_ENGINE();}
export function DD5_change(event)   {SEARCH_ENGINE();}
 
export function BTNsearch_click(event)  {SEARCH_ENGINE();}
 
function SEARCH_ENGINE() { 
    let filter =  wixData.filter()  
    let item1, item2, item3, item4, item5, item6, item7
 
  //DD1-DD5 = DropDowns------------------------------------------------------
    if ($w('#DD1').value!=="")  {item1 = $w('#DD1').value}
    if ($w('#DD2').value!=="")  {item2 = $w('#DD2').value}
    if ($w('#DD3').value!=="")  {item3 = $w('#DD3').value}
    if ($w('#DD4').value!=="")  {item4 = $w('#DD4').value}
    if ($w('#DD5').value!=="")  {item5 = $w('#DD5').value}
 
    if (item1!==undefined)      {filter = filter.eq(REFERENCE1, item1)}
    if (item2!==undefined)      {filter = filter.eq(REFERENCE2, item2)}
    if (item3!==undefined)      {filter = filter.eq(REFERENCE3, item3)}
    if (item4!==undefined)      {filter = filter.eq(REFERENCE4, item4)}
    if (item5!==undefined)      {filter = filter.eq(REFERENCE5, item5)}
  //DD1-DD5 = DropDowns------------------------------------------------------
 
    $w(DATASET).setFilter(filter)
    .then(()=>{
        console.log(myFilter)
        result_COUNTER()
       // $w('#table1').refresh();
    })
}
 
function RESET (parameter) {
    $w("#DD1").selectedIndex = undefined;
    $w("#DD2").selectedIndex = undefined;
    $w("#DD3").selectedIndex = undefined;
    $w("#DD4").selectedIndex = undefined;
    $w("#DD5").selectedIndex = undefined;
}

 
//Result-Counter----------------------------------------------
function result_COUNTER() {
    let count = $w(DATASET).getTotalCount().toString();
    console.log("COUNT = " + count)
    $w('#TXTresults').text = count.toString()
}

 
export function BTNbundesland_click(event)  {if($w('#box2').hidden) {$w('#box2').show(), $w('#box4').hide()} else{$w('#box2').hide()}}
export function BTNsprachen_click(event)    {if($w('#box4').hidden) {$w('#box4').show(), $w('#box2').hide()} else{$w('#box4').hide()}}
 
export function BTNset_click(event)         {$w('#box2').hide(), SEARCH_ENGINE();}
export function BTNset2_click(event)        {$w('#box4').hide(), SEARCH_ENGINE();}
 
//Reset_Buttons--------------------------------------------------------------------------
export function BTNreset_click(event)       {RESET(), SEARCH_ENGINE();}
export function BTNreset1_click(event)      {$w("#DD1").selectedIndex = undefined, SEARCH_ENGINE();}
export function BTNreset2_click(event)      {$w("#DD2").selectedIndex = undefined, SEARCH_ENGINE();}
export function BTNreset3_click(event)      {$w("#DD3").selectedIndex = undefined, SEARCH_ENGINE();}
export function BTNreset4_click(event)      {$w("#DD4").selectedIndex = undefined, SEARCH_ENGINE();}
export function BTNreset5_click(event)      {$w("#DD5").selectedIndex = undefined, SEARCH_ENGINE();}
//---------------------------------------------------------------------------------------

@russian-dima I solved it. With just one line. Since resetting the filters would mess with default Editor values, I thought to bypass the problem by just… refreshing! It works!!

$w("#dataset1").onReady( () => {
    $w("#dataset1").refresh();
} );