How to search and filter on the same database

I’m working on a general insurance agency website. There are lots of insurance product and I would like to have a search of product by its name, and also to filter it by business activity using a dropdown menu.

For example, if i search for liability product, all the liability solution will appear in repeater. like professional liability, management liability, marine liability etc.

But when I filter by business activity, different products that are relevant to the business will appear in the repeater. Like for retail, then property insurance, work injury compensation, workers’ bond will appear.

I managed to do the search by keywords with the following code:

import wixData from ‘wix-data’;

let debounceTimer;
export function iProduct_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iProduct’).value);
}, 200);
}

let lastFilterTitle;

function filter(product) {
if (lastFilterTitle !== product) {
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘product’, product))
lastFilterTitle = product;

} 

}

But I couldn’t work out the filter by business activity. Appreciate your help.

2 Likes

I found a solution to it.

https://www.vorbly.com/Vorbly-Code/WIX-REPEATER-WITH-MULTIPLE-FILTERS

Jared Low the only problem is the drop down creates duplicate items, so with larger databases you have a ugly mess of a drop down. Have yet to find anyone with an answer

yes, i noticed that as well. But when i input the value manually in the dropdown bar, somehow it works and doesn’t show the duplicated items in the database.