Load More button not working for data returned from an API

I have a custom block of code that reaches out to an API and renders a repeater with the results that are returned. Because this data is dynamic for each user I can not store it into a database directly and instead am creating an array of objects and passing that value to the repeater directly.

Because of the way Wix repeaters work I do have a database with all the fields that I am using to render to the repeater, however it is always blank.

So far everything works great. I can save my data to a resorts array and render it to the repeater with $w ( “#resortsRepeater” ). data = resorts

The only problem is sometimes there is a LOT of data returned from the API and so I need to implement some sort of pagination. To accomplish this I set up a button and connected it to the same dataset that I have my repeater connected to and set the Click Action to “Load More”. However the repeater still renders all the returned results and the Load More button is greyed out.

How can I limit the amount of items that are displayed by the repeater at one time?

I am assuming you have already checked the API documentation to see if they offer you a pagination parameter on your GET. If you haven’t checked yet, see if they do as that would be the easiest option.

If not and you have to pull all the data at once, you will likely need to slice up the array and on each load more click merge the next chunk of results and return that array to the repeater.

I know you stated that you do not intend to save the API data to a collection, but if you do decide to go this route, you can use a dataset and then hook up a load more option to a button without code.

Unfortunately they do not offer that as an option. I can create a slice function though and that should work alright