infinite scroll with remote data

Select2 supports lazy-appending of results when the result list is scrolled to the end. in order to enable the remote service must support some sort of a paging mechanism and the query function given to Select2 must take advantage of it. the following example demonstrates how this can be set up. search for some keyword & then scroll the result list to the end to see more results load:

eg code:

  1. $(“#e7”).select2({
  2. placeholder: {title: “Search for a movie”, id: “”},
  3. minimumInputLength: 3,
  4. ajax: {
  5. url: “http://api.rottentomatoes.com/api/public/v1.0/movies.json”,
  6. dataType: ‘jsonp’,
  7. quietMillis: 100,
  8. data: function (term, page) { // page is the one-based page number tracked by Select2
  9. return {
  10. q: term, //search term
  11. page_limit: 10, // page size
  12. page: page, // page number
  13. apikey: “ju6z9mjyajq2djue3gbvv26t” // please do not use so this example keeps working
  14. };
  15. },
  16. results: function (data, page) {
  17. var more = (page * 10) < data.total; // whether or not there are more results available
  18. // notice we return the value of more so Select2 knows if more results can be loaded
  19. return {results: data.movies, more: more};
  20. }
  21. },
  22. formatResult: movieFormatResult, // omitted for brevity, see the source of this page
  23. formatSelection: movieFormatSelection // omitted for brevity, see the source of this page
  24. });

42 responses »

  1. picamilon says:

    Really fantastic info can be found on this web blog.

  2. Greeting from across the world. precise post I must return for more.

  3. This publication has inspired me to start working on my own blog

  4. malic acid says:

    Cheers, I just stopped in to visit your site and thought I’d say I enjoyed myself.

  5. nootropic says:

    Very interesting info!Perfect just what I was searching for!

  6. jailbreak says:

    Very interesting information!Perfect just what I was looking for!

  7. jailbreak says:

    Hello, I just stopped by to visit your website and thought I’d say thanks for having me.

  8. Greeting from across the ocean. detailed blog I will return for more.

  9. I consider something really interesting about your weblog so I saved to fav.

  10. antioxidants says:

    I enjoyed your helpful words. topnotch work. I hope you write more. I will carry on watching

  11. You have mentioned very interesting details! ps decent internet site.

  12. d3 items says:

    Hi, i think that i noticed you visited my site so i got here to “go back the prefer”.I’m trying to in finding issues to enhance my website!I assume its ok to make use of some of your ideas!!

  13. click this says:

    Very interesting information!Perfect just what I was searching for!

  14. You have noted very interesting details! ps nice website.

  15. jailbreak says:

    Hey, I just stopped by to visit your website and thought I’d say thank you.

  16. vitamins says:

    Very interesting info!Perfect just what I was searching for!

  17. l-tyrosine says:

    This writing has inspired me to start focusing on my own blog

  18. incontinence says:

    Rattling fantastic information can be found on this blog.

  19. incontinence says:

    Hi, i believe that i saw you visited my blog so i came to “go back the choose”.I’m attempting to to find issues to improve my site!I guess its good enough to make use of some of your concepts!!

  20. l-tyrosine says:

    Very interesting information!Perfect just what I was searching for!

  21. notropics says:

    Greeting from over the world. Great blog I must return for more.

  22. notropics says:

    I enjoyed your rich article. great work. I hope you produce others. I will carry on subscribing

  23. picamilon says:

    Very interesting information!Perfect just what I was searching for!

  24. picamilon says:

    Really wonderful info can be found on this website.

  25. I consider something truly interesting about your weblog so I saved to bookmarks .

  26. Minimalist sites load faster, get fewer server resources, and are usually faster to develop than more graphically complicated designs
    The key to a lovely minimalist web site is usually a solid and structured layout, as well as focus on stylish and well designed typography.

  27. Thu Fonger says:

    Thanks for your your content – really interesting. We love our Kindle and the best site for tips and tricks is coolkindles.

  28. I stumbled upon this via Bing. This web page appears great.

  29. nootropics says:

    Cheers, I just stopped by to visit your site and thought I’d say thanks for having me.

  30. nootropic says:

    You have noted very interesting points! ps decent internet site.

  31. Kent Sprau says:

    Incredibly useful list of tools. Many thanks for sharing.. i never heard of some of them. Bookmarked this for future reference if i ever need to use these apps.
    I used the twitter just one not also long a go and it is incredibly useful!Thanks for sharing these

  32. I consider something really interesting about your web site so I saved to bookmarks .

  33. Rory Deuink says:

    Thanks a bunch for sharing this with all folks you genuinely realize what you are talking about! Bookmarked. Please also seek suggestions from my web web-site =). We may well have a link alternate agreement between us!

  34. aion kinah says:

    Sup take a look at my trackback when you have a second

  35. I’m now not positive where you are getting your info, but good topic. I must spend a while studying more or understanding more. Thank you for great info I used to be searching for this info for my mission.

  36. Hey I considered you may enjoy my guide

  37. This is the type of site I love to see! Smartly written, it’s super!

  38. Online sales cheap digital camera batteries and charger company’s global delivery of quality value of the letter lazy ~!

  39. Woah nice article. Just what I needed for dis essay I’m working on. Many thanks!

  40. AWF52bIewq says:

    Souls in the Waves

    Fantastic Early morning, I just stopped in to go to your website and believed I’d say I liked myself.

As salam. Hi. Leave a Comment?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s