search dataset not database

Hi there, I’ve used the following code to set up the search bar on my site.
Unfortunately, when I use the search, it pulls up the data from the database, not just through the filtered dataset.
Please help me. I’m new to this, so you have to talk in plain English - LOL!
The database is CompanyInfo & the dataset is #dataset1.
I’d really appreciate any help.
Many thanks
Sarah

Hi Sarah and welcome to Wix Code :slight_smile:
There is a method called setFilter to dataset elements.
This thread is for you.
For more information:

Good luck!
Roi

Thanks, Roi, I’ll check it out now. Much much appreciated!


Hi Roi, I tried this code but it doesn’t work. I just want my dataset to refresh to its original filters if the input field is NULL for the search bar.
At the moment, when I clear the search bar, the table reverts to display my full database, not just the original filtered dataset.
Any assistance would be greatly appreciated!

Hi Sarah,

You can try to change line 18 - 22

if ( res.items.length > 0) {
$w(“#table1”).row = res.items;
}

Hope useful.

About input field is null,
The easy way to do so, I suggest you can add a cancel button and a click event.

export function cancelButton_click() {
$w(“#input1”).value = null;
wixData.query(“CompanyInfo”).find.then( (res2)=> {
$w(“#table1”).rows = res2.items;
});
}

Thanks so much! I really appreciate your help :blush: