Skip to content

Instantly share code, notes, and snippets.

@shanwixcode
Created June 30, 2020 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanwixcode/8326b89955a8478f2b521272bc949517 to your computer and use it in GitHub Desktop.
Save shanwixcode/8326b89955a8478f2b521272bc949517 to your computer and use it in GitHub Desktop.
import wixData from 'wix-data';
$w.onReady(function () {
});
export function dataset1_ready() {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
$item("#price").text = itemData.price + ' ' + itemData.currency;
});
}
let lastFilterName;
let lastFilterPrice;
let debounceTimer;
function filter(name, price) {
if (lastFilterName !== name || lastFilterPrice !== price) {
let newFilter = wixData.filter();
if(name)
newFilter = newFilter.contains('name', name);
if(price)
newFilter = newFilter.le('price', price);
$w("#dataset1").setFilter(newFilter);
lastFilterName = name;
lastFilterPrice = price;
}
}
export function searchBar_keyPress(event) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w("#searchBar").value, lastFilterPrice);
}, 200);
}
export function slider1_change(event) {
let num = Number($w('#slider1').value);
filter(lastFilterName, num);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment