Hello,
I am creating my online store and trying to add filter functions by corvid.
Currently, I followed this Youtube video and it has done for search bar.
https://www.youtube.com/watch?v=mTRSPNosLRw&t=39s
However, I couldn’t connect to Products collection’s collections field.
The store filter function doesn’t have a keyword search bar that I am trying to build a Repeater Dataset way.
I am wondering, how can I add a collections field sort function by corvid?
collections field returns “undefined” value that it didn’t work hasSome() filter.
This is my current code.
import wixData from ‘wix-data’;
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
$w.onReady(function () {
//TODO: write your page related code here…
wixData.query(‘Stores/Collections’)
.find()
.then(res => {
let options = [{“value”: ‘’, ‘label’:‘All Catalog’}];
options.push(…res.items.map(catalog => {
return {‘value’: catalog.name, ‘label’: catalog.name}
} ));
$w(‘#catalog’).options = options;
})
});
//filter by keyword
let lastFilterTitle;
let lastFilterCatalog;
let debounceTimer;
export function search_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(()=>{
filter($w(‘#search’).value, lastFilterCatalog);
}, 200);
}
function filter (title, catalog) {
if (lastFilterTitle !== title || lastFilterCatalog !== catalog) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘name’, title);
if (catalog)
newFilter = newFilter.hasSome('collections', catalog);
$w('#dataset1').setFilter(newFilter);
lastFilterTitle = title;
lastFilterCatalog = catalog
}
}
//filter by category
export function catalog_change_1(event) {
filter(lastFilterTitle, $w(‘#catalog’).value);
}
Hopefully, this article can overwhelm the forum.
Many thanks