Count text box does not work

Hi, the function count() does not work and I don’t understand why. How can I make this work?

import wixData from ‘wix-data’ ;

$w . onReady (() => {
$w ( “#dropdown1, #dropdown2, #dropdown3” ). onChange ( function () {
search ();
});
});

function search ( ) {

wixData . query ( "Properties" ) 
    . contains ( "typeDoffre" ,  String ( $w ( "#dropdown1" ). value )) 
    . and ( wixData . query ( "Properties" ). contains ( "propertieType" ,  String ( $w ( "#dropdown2" ). value ))) 
    . and ( wixData . query ( "Properties" ). contains ( "adresse" ,  String ( $w ( "#dropdown3" ). value ))) 
    //--------- COPY AND PASTE FROM THE .and() TO THE NEXT LINE TO ADD CODE FOR MORE DROPDOWN 

    . find () 
    . then ( results  => { 
        $w ( "#propertiesRepeater" ). data  =  results . items ; 
    }); 

//CLEAR FILTER 
$w ( "#ClearSearchAchat" ). onClick ( **function**  () { 

    $w ( "#dropdown1" ). value  =  **undefined** ; 
    $w ( "#dropdown2" ). value  =  **undefined** ; 
    $w ( "#dropdown3" ). value  =  **undefined** ; 

    $w ( "#propertiesDataset" ). setFilter ( wixData . filter ()); 

}); 

}

function count ( ) {

**let**  total  =  $w ( '#propertiesDataset' ). getTotalCount (); 
**if**  ( total  >  1 ) { 

    $w ( '#CountTextAchat' ). text  =  ` ${ total }  results were found.` ; 
    $w ( '#CountTextAchat' ). show (); 

} 

**if**  ( total  ===  1 ) { 
    $w ( '#CountTextAchat' ). text  =  ` ${ total }  result was found.` ; 
    $w ( '#CountTextAchat' ). show (); 
} 

**if**  ( total  ===  0 ) { 
    $w ( '#CountTextAchat' ). text  =  "No result found!" ; 
    $w ( '#CountTextAchat' ). show (); 

} 

}

Well you never get a total-count, because you never start the → COUNT-function ←
in your code.

import wixData from 'wix-data';

$w.onReady(() => {
    $w("#dropdown1, #dropdown2, #dropdown3").onChange(function () {
        search();
    });
});

function search() {
    wixData.query("Properties")
        .contains("typeDoffre", String($w("#dropdown1").value))
        .contains("propertieType", String($w("#dropdown2").value))
        .contains("adresse", String($w("#dropdown3").value))
        .find()
        .then(res => {console.log(res);
            $w("#propertiesRepeater").data = res.items;
        });

    //CLEAR FILTER
    $w("#ClearSearchAchat").onClick(function () {
        $w("#dropdown1, #dropdown2, #dropdown3").value = undefined;
        $w("#propertiesDataset").setFilter(wixData.filter());
    });

}

function count() {//<--- this function never gets fired!
    let total = $w('#propertiesDataset').getTotalCount();
    if (total > 1) {
        $w('#CountTextAchat').text = `${total} res were found.`;
        $w('#CountTextAchat').show();
    }

    if (total === 1) {
        $w('#CountTextAchat').text = `${total} result was found.`;
        $w('#CountTextAchat').show();
    }

    if (total === 0) {
        $w('#CountTextAchat').text = "No result found!";
        $w('#CountTextAchat').show();
    }
}

Another problem i see, is that you are mixing Wix-Data-API with DATASET.
This is not the best idea! Either go the one or the other way.
Mixing both will let you get some troubles.

What should I change for the count function to gets fired and how can I fix the mixing of WixData and Dataset?
I’m new to this and this is very tricky to solve :confused:

import wixData from 'wix-data';

$w.onReady(() => {
    $w("#dropdown1, #dropdown2, #dropdown3").onChange(function () {
        search();
    });
});

function search() {console.log("Search-Engine running...");
    wixData.query("Properties")
        .contains("typeDoffre", String($w("#dropdown1").value))
        .contains("propertieType", String($w("#dropdown2").value))
        .contains("adresse", String($w("#dropdown3").value))
        .find()
        .then(res => {console.log("My-RESULTS:" , res);
            $w("#propertiesRepeater").data = res.items;
            count();
        });

    //CLEAR FILTER
    $w("#ClearSearchAchat").onClick(function () {
        $w("#dropdown1, #dropdown2, #dropdown3").value = undefined;
        $w("#propertiesDataset").setFilter(wixData.filter());
    });

}

function count() {console.log('Counter running...');
    let total = $w('#propertiesDataset').getTotalCount();
    if (total > 1) {
        $w('#CountTextAchat').text = `${total} res were found.`;
        $w('#CountTextAchat').show();
    }

    if (total === 1) {
        $w('#CountTextAchat').text = `${total} result was found.`;
        $w('#CountTextAchat').show();
    }

    if (total === 0) {
        $w('#CountTextAchat').text = "No result found!";
        $w('#CountTextAchat').show();
    }
}