I have got two problems.
I designed a search page where you can search for student refugee projects by location and by school name.
-
I notice the search takes a while before the filtered results display. How can I fix this? P.S I already reduced the number of items displayed per page to 15.
-
I will like to display a message on the page if no records was found after search. I placed a box over the repeater, made it hidden and code it in such a way that it displays when no item is returned (i retrieved the totalcount of the dataset and check if its 0, then the box shows if its 0). for some reason, it doesn’t work. sometimes the box shows with the repeater, sometimes the box shows alone.
I used console.log to show me how many items counted from the dataset. The numbers just don’t match with the number of items displayed on the page.
Here is a link to the search page: https://uidnetherlands.wixsite.com/muctwebsite/post-search
Here is my Code for that page:
import wixData from ‘wix-data’;
$w.onReady(function () {
//TODO: write your page related code here…
});
let debounceTimer;
export function wordsearch_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#wordsearch’).value, $w(‘#locationsearch’).value);
}, 200);
}
function filter(schoolname, location) {
let newFilter = wixData.filter();
if (schoolname)
newFilter = newFilter.contains('nameOfInstitution', schoolname);
if (location)
newFilter = newFilter.eq('location', location);
$w('#dataset1').setFilter(newFilter);
$w("#dataset1").onReady( () => {
let items = $w('#dataset1').getTotalCount();
console.log(items);
if (items === 0)
$w('#box1').show('Bounce-In');
} );
}
export function locationsearch_change(event, $w) {
//lastFilterWord === null;
$w(‘#wordsearch’).value = null;
filter($w(‘#wordsearch’).value, $w(‘#locationsearch’).value);
}
export function wordsearch_onfocus(event, $w) {
$w(‘#locationsearch’).value = null;
}