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.