I have set up a page with three repeaters that are connected to three different datasets. I have created a search bar that allows me to search on 1 element per repeater, but I need to be able to search on all of them. When I try to add more, its seems that the code is looking for the search criteria to be in both the elements, rather than either. So I need to know how to create an OR search?!
My code is shown below.
import wixData from ‘wix-data’;
let debounceTimer;
export function input1_keyPress(event, Sw) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#input1’).value);
}, 200);
}
let lastfilterTitle;
function filter(title) {
if (lastfilterTitle !== title) {
filter($w(‘#input1’).value);
function filter(input1) {
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘description’, input1));
$w(‘#dataset2’).setFilter(wixData.filter().contains(‘description’, input1));
$w(‘#dataset3’).setFilter(wixData.filter().contains(‘notes’, input1));
lastfilterTitle = title;
If I simply add another line (for example)
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘title’, input1));
Then the search does not work.
Can anyone help?
Thank you
Kind regards
Jenny
Have a read of setFilter as you can’t use two on the same dataset as in theory you would be setting it once and then basically setting it again straight afterwards.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFilter
Setting a dataset’s filter overrides existing filters that were previously set using the setFilter() function or using the Dataset Settings panel in the Editor.
Why not just do a data query on all of them and then maybe set the dataset to be filtered by the result.
https://www.wix.com/corvid/reference/wix-data.html#query
https://www.wix.com/corvid/reference/wix-data.WixDataFilter.html
Thank you so much for taking the time to reply. Having looked at the recommended links I can see that a query could be the answer I need, but I do not know how to make the coding work.
I need a search bar that allows someone to enter any free text, and the coding to search all the repeater elements on that page and show only the ones that contain the required information. I have tried copying the code form the WixDataFilter page into my website, but it doesn’t work. I’m really new to coding and don’t understand a lot of it, the above coding was copied and pasted from various tutorial pages, and then I just adapted slightly. Are you able to help with more specific coding? Thank you again for your time, very much appreciated.
You can find a good many Wix examples here.
https://www.wix.com/corvid/examples
Or use the search function on the top right to find previous posts about code things that might contain blocks of code or helpful hints that can help you with your own site.