OnReady function frustration

I have obviously an issue :slight_smile: I have a repeater that is connected to a database. Furthermore I have two dropdowns with perfectly working onChange functions. HOWEVER I would need a function that shows the database without duplicates in a specific field when the page loads as I have multiple entries. Does anybody have an idea?

Many thanks for your help in advance.

Cheers,
Mario

Can you re-phrase your question, so it’ll be easier to understand?
Please add examples etc…

Hi J.D.

Below is my perfectly working code. As seen in the picture the row (firma) has the same value (for example “41medical”) multiple times. Whenever my website loads it shows the multiple entries. However I would like it to show “41medical” only one time when the page loads.

import wixData from ‘wix-data’;

let debounceTimer;
export function iTitle_keyPress(event, $w) {
let SearchValue = $w(“#iTitle”).value;
$w(“#dataset1”).setFilter(wixData.filter().contains(‘hauptkategorie’ , SearchValue)
.or(wixData.filter().contains(‘subkategorie’ , SearchValue)
.or(wixData.filter().contains(‘firma’ , SearchValue)
)))
}

if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
}, 200);

$w.onReady( function () {
uniqueDropDown1();
uniqueDropDown2();
repeater();
});

function repeater (){
wixData.query(“Memberlistev2”)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#repeater1”).options = buildOptions(uniqueTitles);
});

function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.firma);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}

function uniqueDropDown1 (){
wixData.query(“Memberlistev2”)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#dropdown1”).options = buildOptions(uniqueTitles);
});

function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.hauptkategorie);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}

export function dropdown1_onChange(event) {
$w(“#dataset1”).setFilter( wixData.filter()
.eq(“hauptkategorie”, $w(“#dropdown1”).value)
);
uniqueDropDown2();
}

function uniqueDropDown2 (){
wixData.query(“Memberlistev2”)
.contains(“hauptkategorie”, $w(“#dropdown1”).value)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#dropdown2”).options = buildOptions(uniqueTitles);
});

function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.subkategorie);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}

export function dropdown2_onChange(event) {
$w(“#dropdown2”).enable();
locationBereichFilter2();
}

function locationBereichFilter2 (){
$w(“#dataset1”).setFilter( wixData.filter()
.eq(“subkategorie”, $w(“#dropdown2”).value)
.contains(“hauptkategorie”, $w(“#dropdown1”).value)
);
}

export function clearFIlters_onClick(event) {
$w(“#dataset1”).setFilter(wixData.filter(undefined));
$w(“#dropdown1”).value = 0;
$w(“#dropdown2”).value = 0;
$w(“#iTitle”).value = “”;
}

Please disregards below code which I am currently playing around in order to solve this:
function repeater (){ wixData.query(“Memberlistev2”) .limit(1000) .find() .then(results => { const uniqueTitles = getUniqueTitles(results.items); $w(" #repeater1 ").options = buildOptions(uniqueTitles); }); function getUniqueTitles(items) { const titlesOnly = items.map(item => item.firma); return [… new Set(titlesOnly)]; } function buildOptions(uniqueList) { return uniqueList.map(curr => { return {label:curr, value:curr}; }); } }

I am very much looking forward to your help chief.

I’m not sure I fully understand the issue.
But why won’t you query the database with .distinct(“firma”) ?
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#distinct
Then assign the result to the desired element?

Hi J.D.

I have multiple entries with the same value in the collumne “firma”. When the website loads it should only display the entries without duplicates.

How are you currently retrieving the data to display? Dataset? Data query?

@jonatandor35 I have a repeater that fetches the data from the dataset.

@ladanimario I see.
So there’re several ways to deal with it.
One way is to get the repeater data and then remove the duplicates and populate it again (I’d go for another direction but it’s more complicated to explain).
So:

$w.onReady( function() {
$w("#dataset1").onReady( () => {
let data = $w("#repeater1").data;
let newData = [];
data.forEach(e => {
if (!newData.some(o => o.firma === e.firma)){//<<<UPDATED THIS LINe
    newData.push(e);
}
})
$w("#repeater1").data = newData;
})
})

@jonatandor35 First of all, thanks a lot for your help. I really appreciate it. However it gives me the following error.

@ladanimario sorry. add a closing parentheses before this line ) after the curly }
and let me know if it worked (I didn’t test it, just wrote it right here)

@jonatandor35 It solved the issue but when I test run it, it does not load the database anymore.

I see. that what happens when you don’t check your code…sorry, I had another error. Fixing it right now.

Let me know if it’s ok now

@jonatandor35 Hombre, you almost did it. It got rid of the duplicates, however now it only shows like 6 entries instead of 659 or so. Here is a screenshot

Forget it - it kinda works now!!! Where are u from. Beer, Martini anything is on me

@ladanimario you’re welcome :slight_smile:

Broooooooooooooooooooooooooooo, when I click the reset button the duplicated show up again. Anything you could help me with?

Many thanks,
Mario

@jonatandor35 heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeelp :frowning:

What does your reset button do?