Pagination Bar does not avoid duplicates in dataset

Hi to my Gurus in this forum. I NEED YOUR HELP.

I have a repeater that is connected to my dataset which has many duplicates. As I have over 200 records in my dataset I have implemented a pagination bar to show 12 items per page and then click to the other page. My current code already avoids duplicates when the page loads. However when I click on the pagination bar to go to the next page, the duplicates come up again.

Please fellas, I need your help!

What’s your current code?

Hi David, Thanks a lot for your help. Here is my current code that works with one dataset and three dropdowns. The only thing is the pagination bar. When I click on pagination, the duplicates come up again. The pagination abris linked to the dataset.

Many thanks,
Mario

import wixData from ‘wix-data’;

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

}

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

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

});

function omitDuplicates() {
let data = $w(“#repeater1”).data;
let newData = ;
data.forEach(e => {
if (!newData.some(o => o.firma === e.firma)){
newData.push(e);
}
})
$w(“#repeater1”).data = newData;
}

$w.onReady( function () {
$w(“#dataset1”).onReady( () => {
omitDuplicates();
})
})

function uniqueDropDown1 (){
wixData.query(“Memberlistev2”)
.ascending(“hauptkategorie”)
.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};
});
}
}

function uniqueDropDown2 (){
wixData.query(“Memberlistev2”)
.contains(“hauptkategorie”, $w(“#dropdown1”).value)
.ascending(“subkategorie”)
.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};
});
}
}

function uniqueDropDown3 (){
wixData.query(“Memberlistev2”)
.contains(“hauptkategorie”, $w(“#dropdown1”).value)
.contains(“subkategorie”, $w(“#dropdown2”).value)
.ascending(“kanton”)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#dropdown3”).options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.kanton);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}

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

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

export function dropdown3_onChange(event) {
uniqueDropDown3();
locationBereichFilter3();
}

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

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

export function clearFIlters_onClick(event) {
$w(“#dropdown1”).value = 0;
$w(“#dropdown2”).value = 0;
$w(“#dropdown2”).disable();
$w(“#dropdown3”).value = 0;
$w(“#dropdown3”).disable();
$w(“#dataset1”).setFilter(wixData.filter())
.then(() => {//<< You need this “then”
$w(“#iTitle”).value = “”; omitDuplicates();
})
}

@ladanimario It’s probably a timing issue, so the quick and dirty solution might be to insert async await to make sure the repeater data is set first.

Or you can try

function omitDuplicates(data) {
let newData = [];
data.forEach(e => {
if (!newData.some(o => o.firma === e.firma)){             newData.push(e);             
}         
})    
$w("#repeater1").data = newData; 
}

and pass a data object every time the function is called.

@skmedia Hi David,
Thanks a lot for your feedback.

Unfortunately I am quite a noob and do not know exactly what to amend.

Could you kindly help.

In the meantime, I have amended this code. The funny part ist when I click on next, I can see the duplicates, but when I go back (for example from page 4 to 3) it automatically avoids the duplicates.

export function pagination1_click(event) {
$w(“#dataset1”).onReady( () => {
omitDuplicates();
})
}

I would need somthing that when I call the next page of the repeater, the code automatically avoids duplicates. I am extremely desperate as I am sooo close to the finish line.

Thanks a lot for your help.

Cheers,
Mario