I have a page that loads data from 2 different databases and combines them in one repeater. Since I’m not using a dataset, how would I add a “load more” function to this should there be additional results than what are initially loaded?
I have a box that uses onViewportEnter that I’ve used on other pages that do have datasets, so I would like to use that as my trigger.
Here is what I would do in this case. First create two global variables above the onReady function and set both their values to empty arrays.
For the sake of example we will refer to them as the following:
let returnedData = []
let repeaterData = []
When you return the data from the queries and concatinate them into one array you can assign returnedValue as the contactinated array.
Now when you want to render the data to the repeater you can use the following function:
export function populateRepeater() {
if(returnedData.length > 10) {
for(let i = 0; i < 10; i++) {
let indexedItem = returnedData.shift()
repeaterData.push(indexedItem)
}
} else {
for(let i = 0; i < returnedData.length; i++) {
let indexedItem = returnedData.shift()
repeaterData.push(indexedItem)
}
}
$w("#listRepeater").data = repeaterData
}
this function gives you a nice chunk of 10 items that will be pushed to the repeater at one time. Because we are directly mutating global variables their values will remain constant meaning you can easily add a button under the repeater and then bind the onClick handler to this function. When the results are returned just await this function call and your repeater will be populated with the first 10 items, and every time you click the load more button 10 more items will be added to the repeater.