Display "sorry no results message" after filtering

Hi guys,
I got a search module, like property search, with dropdown, and a "find button, all results appears in a repeater. i would like to display a message no results in case of no data.
here is my code, please can you tell me with code i have to add and where, super thx in advance…

here is my code :
import {wixData} from ‘wix-data’;

export function button1_click(event, $w) {
$w(“#dataset1”).setFilter(wixData.filter()

    .contains("nomDuBien", $w('#dropdown5') .value) 
    .ge("pieces", $w('#dropdown2') .value) 
    .contains("jardin", $w('#radioGroup1').value) 
    .between("surface",parseFloat($w('#dropdown6').value), parseFloat($w('#dropdown7').value)) 
    .between("price",parseFloat($w('#dropdown3').value), parseFloat($w('#dropdown4').value))) 


.then((results) => { 
        console.log("Dataset is now filtered");  
        $w("#repeater1").data = results.items; 
    }). **catch** ((err) => { 
        console.log(err); 
    }); 
$w("#repeater1").expand(); 

}

// code code etc..... and then:
  .then((results) => {
 results.items.length === 0 ? $w(#"textMessege").text =  "sorry no results" : $w("#repeater1").data = results.items;
   }) 

Thanks you quick answer, her’s what i got no w:
I’ve inserted the line : results.items.length === 0 ? $w(#“textMessege”).text = “sorry no results” :
Says that (#'textMessege") is not a valid selector…

It was an example. You should put there the property name of you text box instead.

That’s what I thought… but i’m No good in code so I behave ! thanks A lot.

Sorry sir, but it doesn’t work, my text (text81) just stay as is… maybe the text shoud have some special properties…?

.then((results) => {
console.log(“Dataset is now filtered”);
results.items.length === 0 ? $w(“#text81”).text = “sorry no results” :
$w(“#repeater1”).data = results.items;

    }). **catch** ((err) => { 
        console.log(err); 
    }); 

$w(“#repeater1”).expand();
}

I’m sad, it was almost done.

If it’s a dataset, you can try, a slightly different code:

.then((results) => {
$w("#myDataset").getTotalCount() > 0 ?   $w("#repeater1").data = results.items : $w("#text81").text =  "sorry no results";
})

I try this now, let you know…

Any way, you may want to hide the repeater if there’s no result. In that case you can do:

.then((results) => {
If($w("#myDataset").getTotalCount() > 0) {
$w("#repeater1").expand();
$w("#text81").collapse();
$w("#repeater1").data = results.items;
} else {
$w("#repeater1").collapse();
$w("#text81").expand();
$w("#text81").text = "sorry no results";
}
})

Congrats JD, This code’s working smoothly :

.then((results) => {
$w(“#myDataset”).getTotalCount() > 0 ? $w(“#repeater1#repeater1 “).data = results.items : $w(”#text81").text = “sorry no results”;
})

But the only thing is : when there’s results, the text “sorry no results” stay still… i need also the code on the other side, so when there is results, a texte “here is your results” replace the “sorry no results”

When there is no results, my repeater hide itself automatically

here is the code i created on your advice and working lovely : so i got same text (text80) that displays “no results” when no results, and “voici vos résultats” (french :slight_smile: when there’s at least 1 result :

.then((results) => {
if ($w(“#dataset1”).getTotalCount() > 0) {
$w(“#repeater1”).expand();
$w(“#text80”).text = “Voici vos résultats”;
$w(“#repeater1”).data = results.items;
} else {
$w(“#repeater1”).collapse();
$w(“#text80”).text = “sorry no results”;
}
}). catch ((err) => {
console.log(err);
});

}

I have tried to follow this but I’m still having problems.
All I’m trying to achieve at the moment is to write to the console the number of records. I can make this happen but it is always one step behind.

With no filter I have 300 records.

I filter the gallery down to 29 records the console prints 300 (29 images are shown in the gallery)
I filter again down to 17 records the console prints 29 (17 images are shown in the gallery)

Any ideas?

Be sure you put it inside the .then() part of the promise.

Thanks J.D.

But where/how I’m still getting errors. This is my code

export function iUpdate_click(event) {
filter($w(‘#iBorough’).value,$w(‘#iDistrict’).value,$w(‘#iType’).value)
}

function filter(borough,district,type){
$w(‘#dataset1’).setFilter(wixData.filter()
.contains(‘borough’,$w(‘#iBorough’).value)
.contains(‘district’,$w(‘#iDistrict’).value)
.eq($w(‘#iType’).value, true )
)

}

First of all, I don’t know why you bother to pass parameters to the filter() function if you don’t use them inside the function at all.
Second, without seeing the error messages, I think I won’t be able to help.
Third, I don’t see the .then() part, and without it nothing is going to happen (the dataset will get filtered but you won’t see the filtering effects).

Hi, I don’t know whether you are still working on this matter, but I have come up with an easy solution for this with out the code.

If there is no data then repeater will not be displayed automatically

So, what you need to do is,

Just put a text box with “Sorry, No data” behind your repeater and bring your repeater forward. So, when there is data your repeater will be shown up and when there is no data repeater will be automatically hid, so your text box will be displayed.