Hi everybody. I've managed to implement some code to add a simple search bar to a dynamic page + list repeater to use as a products gallery. I'm using the WixStores "Products" dataset. I'd like to be able to force the repeater to only show one collection on loading and for the searchbar to only search that collection rather than bringing up all products in the dataset.
The user will not be able to switch collections on a dropdown, the page will simply display one collection and I'll then dedicate a similar page to another collection and so on... I'm a total novice to code and I've searched the internet high and low for a way of doing this without any luck. Thanks!
Here's the code I'm using:
import wixData from 'wix-data';
$w.onReady(function () {
//TODO: write your page related code here...
});
let debounceTimer;
export function searchBar_keyPress(event) {
$w("#loadingGif").show();
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
$w("#dataset1").setFilter(wixData.filter().contains("name", $w('#searchBar').value)
.or(wixData.filter().contains("sku", $w('#searchBar').value)
))
.then(() => {
count();
})
}, 200);
}
function count() {
let total = $w('#dataset1').getTotalCount();
if (total > 1) {
$w('#textResults').text = `${total} results were found.`;
$w("#loadingGif").hide();
$w('#textResults').show();
}
if (total === 1) {
$w('#textResults').text = `${total} result was found.`;
$w("#loadingGif").hide();
$w('#textResults').show();
}
if (total === 0) {
$w('#textResults').text = "No result found!";
$w("#loadingGif").hide();
$w('#textResults').show();
}
}
Nobody? :-(