Dataset filter returns wrong TotalCount

I have got two problems.

I designed a search page where you can search for student refugee projects by location and by school name.

  1. 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.

  2. 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;
}

Hi,
To get the number of the items returned from the filter you can use " query .count ", create a query with the same conditions of the filter to get the number of items returned.

Good luck:)

Okay, Thanks for the response. I will do that…but i have another question.

i read a field from database into a text element; Now, I want to assign the “text value of the text element” to the the “value of a textbox element”. The value of the textbox doesn’t change still.

here is what i did

$w.onReady(function () {
//TODO: write your page related code here…
$w(“#Dataset1”).onReady( () => {
$w(‘#input4’).value = $w(‘#text45’).text;

  }); 

});

Hi Or,

The “query.count” solution worked! Thank you!
do you know why it takes a while for the filtered results to show?