Last active
July 5, 2020 10:45
-
-
Save shanwixcode/39d6eda05159936a941d8dd26ec8b6e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wixData from 'wix-data'; | |
$w.onReady(function () { | |
}); | |
export function repeater1_itemReady($item, itemData, index) { | |
$item("#price").text = itemData.price + ' ' + itemData.currency; | |
} | |
export async function name_keyPress(event) { | |
defaultSort = await false; | |
if (debounceTimer) { | |
clearTimeout(debounceTimer); | |
debounceTimer = undefined; | |
} | |
debounceTimer = setTimeout(() => { | |
filter($w("#name").value, collectionName); | |
}, 200); | |
} | |
export async function collection_change(event) { | |
defaultSort = await false; | |
filter(filterName, $w("#collection").value); | |
} | |
export async function sortBy_change(event) { | |
defaultSort = await false; | |
if($w("#sortBy").value === 'A-Z') { | |
$w("#dataset1").setSort(wixData.sort() | |
.ascending("name") | |
); | |
} else if($w("#sortBy").value === 'Z-A') { | |
$w("#dataset1").setSort(wixData.sort() | |
.descending("name") | |
); | |
} else if($w("#sortBy").value === 'New to Old') { | |
$w("#dataset1").setSort(wixData.sort() | |
.ascending("_updatedDate") | |
); | |
} else if($w("#sortBy").value === 'Old to New') { | |
$w("#dataset1").setSort(wixData.sort() | |
.descending("_updatedDate") | |
); | |
} else if($w("#sortBy").value === 'Price High to Low') { | |
$w("#dataset1").setSort(wixData.sort() | |
.descending("price") | |
); | |
} else if($w("#sortBy").value === 'Price Low to High') { | |
$w("#dataset1").setSort(wixData.sort() | |
.ascending("price") | |
); | |
} | |
} | |
let defaultSort = false; | |
export async function reset_click(event) { | |
$w("#name").value = await undefined; | |
$w("#collection").value = await undefined; | |
$w("#sortBy").value = await undefined; | |
defaultSort = await true; | |
filter(); | |
} | |
export function dataset1_ready() { | |
let count = $w("#dataset1").getTotalCount(); | |
$w("#count").text = 'Total Products: (' + count + ')'; | |
} | |
let filterName; | |
let collectionName; | |
let debounceTimer; | |
async function filter(name, collection) { | |
if(filterName !== name || collectionName !== collection) { | |
let newFilter = wixData.filter(); | |
if(name) | |
newFilter = newFilter.contains('name', name); | |
if(collection) | |
newFilter = newFilter.hasSome('collections', [collection]); | |
await $w("#dataset1").setFilter(newFilter); | |
if(defaultSort === true) { | |
$w("#dataset1").setSort(wixData.sort() | |
.ascending("name") | |
); | |
} | |
let count = $w("#dataset1").getTotalCount(); | |
$w("#count").text = 'Total Products: (' + count + ')'; | |
filterName = name; | |
collectionName = collection; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment