After pagination click, I lose my forEachItem function on a repeater...

Hi All, Marco here! I am writing with a small issue that I think is related to the timing of events, more than code (which I think I have a working version of) and I don’t have enough knowledge to tackle.

I have a classical Database>Dataset>Filter>Repeater structure that works well. The filter is controlled by a search bar and keywords and works well, but having 653 entry I need a pagination structure. Easy fix just with the graphical editor. My problems lie within the need of performing a forEachItem on the repeater, to assess the status of 8 boolean fields that control the appearance/disappearance of images on each of the repeater elements.

The code I have for the forEachItem works, but only on the first set of elements. Clicking on the pagination will reload the new results but the images are not checked anymore.

I tried my code in three positions: in the on ready function after the first general filtering of dataset, I the filtering function itself (triggered by the click on search button), or after a onclick event on the pagination bar. Nothing works!! Any idea???

#foreachitem #repeater #pagination #dataset #filter #boolean

$w.onReady(function () {
    $w("#searchBar").value = "";
    $w("#searchBar").placeholder = "calcium, ER, mitochondria...";
    $w("#dataset1").onReady(function () {
        search();
        // I THOUGHT THAT AS SOON AS SEARCH FUNCTION (WHICH IS MY FILTER) IS APPLIED THEN IT WAS THE RIGHT MOMENT FOR THE forEachItem on the repeater
        $w("#repeater1").forEachItem(($item, itemData, index) => {
                let mtfield = itemData.mt;
                    if (mtfield === true) {
                        $item("#MT").show();
                    } else {
                        $w("#MT").hide();
                    }
                let gcfield = itemData.gc;
                    if (gcfield === true) {
                        $item("#GC").show();
                    } else {
                        $w("#GC").hide();
                    }
                let esfield = itemData.es;
                    if (esfield === true) {
                        $item("#ES").show();
                    } else {
                        $w("#ES").hide();
                    }
                let ghfield = itemData.gh;
                    if (ghfield === true) {
                        $item("#GH").show();
                    } else {
                        $w("#GH").hide();
                    }
                let sssfield = itemData.sss;
                    if (sssfield === true) {
                        $item("#SSS").show();
                    } else {
                        $w("#SSS").hide();
                    }
                let jhoekfield = itemData.jhoek;
                    if (jhoekfield === true) {
                        $item("#JHOEK").show();
                    } else {
                        $w("#JHOEK").hide();
                    }
                let weavfield = itemData.weav;
                    if (weavfield === true) {
                        $item("#WEAV").show();
                    } else {
                        $w("#WEAV").hide();
                    }
                let jsfield = itemData.js;
                    if (jsfield === true) {
                        $item("#JOS").show();
                    } else {
                        $w("#JOS").hide();
                    }           
    });
});
})

export function searchButton_click(event) {
        search();
}
export function resetButton_click(event) {
        $w('#searchBar').value = ""
        $w('#searchBar').placeholder = "calcium, ER, mitochondria..."
        $w('#counter').hide()
        search()

}

function search() {
    $w('#searchGIF').show();
    $w('#dataset1').setFilter(wixData.filter().contains("title", $w("#searchBar").value)
            .or(wixData.filter().contains("sourceTitle", $w("#searchBar").value)))
            .then(() => {
                // I THOUGHT THAT WITH THE PAGINATION CLICK A NEW SEARCH WOULD BE PERFOMED, SO I TRIED TO PLACE IT HERE
                $w("#repeater1").forEachItem(($item, itemData, index) => {
                let mtfield = itemData.mt;
                    if (mtfield === true) {
                        $item("#MT").show();
                    } else {
                        $w("#MT").hide();
                    }
                let gcfield = itemData.gc;
                    if (gcfield === true) {
                        $item("#GC").show();
                    } else {
                        $w("#GC").hide();
                    }
                let esfield = itemData.es;
                    if (esfield === true) {
                        $item("#ES").show();
                    } else {
                        $w("#ES").hide();
                    }
                let ghfield = itemData.gh;
                    if (ghfield === true) {
                        $item("#GH").show();
                    } else {
                        $w("#GH").hide();
                    }
                let sssfield = itemData.sss;
                    if (sssfield === true) {
                        $item("#SSS").show();
                    } else {
                        $w("#SSS").hide();
                    }
                let jhoekfield = itemData.jhoek;
                    if (jhoekfield === true) {
                        $item("#JHOEK").show();
                    } else {
                        $w("#JHOEK").hide();
                    }
                let weavfield = itemData.weav;
                    if (weavfield === true) {
                        $item("#WEAV").show();
                    } else {
                        $w("#WEAV").hide();
                    }
                let jsfield = itemData.js;
                    if (jsfield === true) {
                        $item("#JOS").show();
                    } else {
                        $w("#JOS").hide();
                    }                   
                count();
            })
    
})
function count() {
    let total = $w('#dataset1').getTotalCount();
    if (total > 1) {
        $w('#counter').text = `${total} results were found.`;
        $w("#searchGIF").hide();
        $w('#counter').show();
    }
    if (total === 1) {
        $w('#counter').text = `${total} result was found.`;
        $w("#searchGIF").hide();
        $w('#counter').show();
    }
    if (total === 0) {
        $w('#counter').text = "No result found!";
        $w("#searchGIF").hide();
        $w('#counter').show();
    }
}}

// MAYBE AFTER THIS?
export function pagination1_click(Event) {  
    
    
} 

Thank you so much!
Marco