Displaying "no results found" on filter search?

I’m trying to have a message, “no results found” for example, when someone does a search and there aren’t any results. So far I’ve been playing with this code but it does the strangest thing. It shows the message on page load and upon searching and getting no results, the message disappears. The opposite of what I want it to do. Any help much appreciated. Thanks.

import wixData from “wix-data”;

export function button4_click(event, $w) {

if (wixData.filter() === 0) {
$w(‘#noResText’).show();
}
else {
$w(‘#noResText’).hide();
}
console.log($w(‘#searchBar’).value);
filter($w(‘#searchBar’).value);
}

function filter() {
$w(‘#dataset1’).setFilter(
wixData.filter()
.contains(“title”, $w(“#searchBar”).value)
.and( wixData.filter()
.contains(“color”, $w(“#dropdown1”).value)
)
);
}

Hi dragos,
There are Several large issues here.

wixData.filter() creates a WixDataFilter object and does not actually contain any results.
The Filter function is called AFTER the site has already checked if there were results, No matter the result it will always display false.

import wixData from "wix-data";  
export function button4_click(event, $w) {
      filter($w('#searchBar').value); 
}  
function filter() {  
    $w('#dataset1').setFilter(  
    wixData.filter()  
    .contains("title", $w("#searchBar").value)  
    .and( wixData.filter()  
    .contains("color", $w("#dropdown1").value)  
    )  
    ).then(()=>{
    if ($w('#dataset1').getTotalCount()===0) {
    $w('#noResText').show();
    } else {
    $w('#noResText').hide()
    }
    }) 
} 

a bit of a re-write

Hey Ethan, thanks for coming to my aid once again. Unfortunately it’s doing the same thing which is displaying the message on page load. It goes away on successful search and comes back on on no results search which is a step in right direction. Perhaps the filtering code i’m using doesn’t really allow for this type of implementation of this function. My other project i’m working on is trying to display how many page numbers of results after a filter search. I’ve searched everywhere for something like this and got nowhere. Also not sure if this code i’m using would allow for it.

like the pic below, currently I only have a previous and next button.

Disregard, I figured it out, the pagination feature from user input that wix offers.

This is an old post, please open a new thread with your problem instead of bumping old posts.