Getting my repeater to show distinct data from a dataset

#repeater #distinct
Hey,
I am writing code for a custom search bar that also has a suggested search. So when a user starts typing a repeater checks for data from a data set and displays results. Some of the data is repeated and I would like for it to show only one.

I have tried using distinct(); but from my understanding that only works for dropdown menus.

repeaterResults is where the final result is shown
searchBar is a text box where the user can type
dataset1 is where the data is being filtered from
repeaterSearch is where the suggestion is being shown.

import wixData from 'wix-data';

$w.onReady(function () {});
export function searchBar_keyPress(event) 
{

    $w("#repeaterResults").data = [];
 
 
    setTimeout(() => {
 if ($w("#searchBar").value.length >= 1) 
          {
              $w("#dataset1").setFilter(wixData.filter().startsWith("area", $w("#searchBar").value))
              .then(() => {
               count();
              })  
          }
 else {
             $w("#repeaterSearch").collapse();

          }
    },500)

}

function count () {
 let total = $w("#repeaterSearch").data.length;

 if (total > 0) {
        $w("#repeaterSearch").expand();
    } else {
        $w("#repeaterSearch").collapse();
    }
 
}

export function repeaterSearch_itemReady($item, itemData, index) 
{

    $item("#area").onClick(() => {

 //$w("#repeaterResults").data = [];
        $w("#searchBar").value = $item("#area").text;
        $w("#repeaterSearch").collapse();
        $w("#repeaterSearch").data = [];

    })

}

@yisrael-wix Any chance you could help?

The distinct() function really doesn’t have anything to do with the Dropdown - rather, it’s part of the WixDataQuery API .

See the Example: Remove duplicates from connected dropdown options using distinct() query which does pretty much what you want to do. It uses the WixData API instead of Wix Dataset.

if ($w("#searchBar").value.length >= 1) 
          {
              $w("#dataset1").setFilter(wixData.query("OurProperties").startsWith("area", $w("#searchBar").value).distinct("area"))
              .then(() => {
               count();
              })  
          }

I updated the code but now I get an error saying “The given filter object is invalid”

@itsdjkcofficial Make sure to read the API documentation that I linked to. The distinct() function is only available on the WixDataQuery API . The example that I linked to illustrates how to use distinct() on a query using the wix-data API .