Hi, I found this a really helpful example to act as a basis for something I am trying to do. However, the dataset/repeater is not filtering.
In principle the inputs and filters seem to work as the “#numberofitems” changes to reflect the search inputs, however it is not being reflected in the repeater, as the items stay the same.
Any help / advice / things to try would be very much appreciated, as Ifeel I have tried everything.
Thanks
Andy
import wixData from ‘wix-data’ ;
let debounceTimer;
$w.onReady( function () {
$w( "#dataset1" ).onReady( () => {
let count = $w( “#dataset1” ).getTotalCount();
$w( “#numberitems” ).text = 'Total: ’ + count;
$w( "#listRepeater" ).onItemReady( ($item, itemData, index) => {
$item( "#compname" ).text = itemData.title;
$item( "#address" ).text = itemData.address;
$item( "#city" ).text = itemData.city;
$item( "#postcode" ).text = itemData.postCode;
$item( "#overallrating" ).number = itemData.overallRating; //not working - work out later
$item( "#numberreviews" ).number = itemData.noReviews; //not working - work out later
});
});
$w( "#cityinput" ).onKeyPress( (event) => {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
// Provide a 350 millisecond interval to allow the site visitor to finish typing
debounceTimer = setTimeout(() => {
filter(lastFilterName, $w( “#cityinput” ).value);
}, 350 );
});
$w( "#venueinput" ).onKeyPress( (event) => {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
// Provide a 350 millisecond interval to allow the site visitor to finish typing
debounceTimer = setTimeout(() => {
filter($w( “#venueinput” ).value, lastFilterCity );
}, 350 );
});
$w( "#clearfilter" ).onClick( (event) => {
filter();
//Reset the filter elements
$w( “#venueinput” ).value = undefined;
$w( “#cityinput” ).value = undefined;
});
});
let lastFilterName;
let lastFilterCity;
async function filter(title, city) {
if (lastFilterName !== title || lastFilterCity !== city) {
let newFilter = wixData.filter( ‘Venues’ );
if (title)
newFilter = newFilter.contains( ‘title’ , title);
if (city)
newFilter = newFilter.contains( ‘city’ , city);
$w( "#dataset1" ).setFilter(newFilter);
let count = $w( “#dataset1” ).getTotalCount();
$w( “#numberitems” ).text = 'Total: ’ + count;
setVariables(title, city);
}
}
function setVariables(title, city) {
lastFilterName = title;
lastFilterCity = city;
}