Last week I released version 2.5 of the Select2 APEX plugin in which I introduced the lazy loading feature. I also wrote a blog post that described in what way you had to apply lazy loading to a Select2 page item. The technique involved consisted of creating an On Demand AJAX process that then had to be referenced in the Remote Data Process item setting. The bad thing about this Remote Data Process was that you had to duplicate the query from the item’s LOV definition to successfully return the query result in JSON format. It was a solution that worked, but my instincts told me there had to be a better way to incorporate lazy loading in the Select2 APEX plugin. However, I wasn’t able to come up with a better solution.

Luckily, Franke Menne wrote a comment on my blog post and was kind enough to show me how I had to improve the lazy loading part. A big thanks to Frank to share his solution and make the Select2 plugin more convenient to use. I’m not going to bother you with the technical adjustments I had to make. I’ll just explain how you can enable lazy loading in the latest version of the Select2 plugin (which is 2.6 on the moment of writing).

First of all, forget about the Remote Data Process I talked about earlier on. We don’t need it anymore, thus no more code duplication. The plugin itself takes care of the JSON generation, completely based on the item’s LOV definition. All we have to do now is check a checkbox when we want to enable lazy loading.

Lazy loading settings
lazy loading settings

That makes it a whole lot easier. I have also added the item setting Lazy-append Row Count. With this number you can determine the amount of results that get lazy-appended to the select list when the result list is scrolled down to the end. An example of this technique can be seen here, under the Infinite Scroll with Remote Data section. Leave this setting empty to disable lazy-appending.