top of page
19 Restaurants
Lamingtons

Lamingtons

Australian

Buffalo Chicken Wings

Buffalo Chicken Wings

American

Barbecued snags

Barbecued snags

Australian

Aloo Gobi

Aloo Gobi

Indian

Tater Tots

Tater Tots

American

Samosas

Samosas

Indian

import wixData from 'wix-data';

 

let debounceTimer;

 

$w.onReady(() => {

 

    $w("#searchInputID").onKeyPress(function () {

 

        $w("#xIconID").show();

 

        $w("#searchInputID").value;

 

        if (debounceTimer) {

            clearTimeout(debounceTimer);

            debounceTimer = undefined;

        }

        debounceTimer = setTimeout(() => {

            filter($w("#searchInputID").value);

        }, 200);

 

    })

 

    let searchWord;

 

    function filter(search) {

        if (searchWord !== search) {

            $w("#datasetID").setFilter(wixData.filter().contains('fieldkey1', search)

                    .or(wixData.filter().contains("fieldkey2", search))

                    //Insert more field filter here ====> here <====

                )

 

                .then(countItems)

            searchWord = search

 

        }

 

    }

 

    //COUNT SEARCH FUNCTION 🚀

    function countItems() {

        let count = $w("#datasetID").getTotalCount()

        count > 0 ? $w("#countTextID").text = `${count} Restaurants` : $w("#countTextID").text = `No Restaurants Found 😥`;

 

        return countItems;

    }

 

    //LOAD COUNT WHEN DATASET IS READY 🎉

    $w("#datasetID").onReady(function () {

        countItems();

    });

 

    // CLEAR SEARCH CODE 🎉

    $w('#xIconID').onClick(() => {

 

        $w("#searchInputID").value = undefined

        $w("#datasetID").setFilter(wixData.filter()).then(countItems())

 

        $w("#xIconID").hide();

 

    })

})

Copied!

bottom of page