top of page
19 Restaurants
Soupe à l’oignon

Soupe à l’oignon

French

Chips & Pastry

Chips & Pastry

Italian

Paris Spaghetti

Paris Spaghetti

French

Potato House Diner

Potato House Diner

Italian

Rolled & Scrambled Eggs

Rolled & Scrambled Eggs

French

The Roasted Chicken

The Roasted Chicken

French

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