I'm attempting to fetch data from MySQL (with a PHP-based API) using Backbone. I want to retrieve items in batches of 20 though. For example, I have 10,000 records, but only want to show 20 records upon page load. As the user scrolls down I'd like to load the next 20 every time they reach the bottom of the page. My query is not sorted by ID (by design), so that may add one level of complexity. How is this possible in Backbone?
1 Answer
I recommend to use this plugin https://github.com/backbone-paginator/backbone.paginator
4 Comments
bentedder
Yeah, have been looking through this, and am connecting to my API fine, but not sure how to set the API get requests to respond to what the paginator sends over (I'm sending data over in json, not jsonp.
Vitalii Petrychuk
This is not a problem, you can configure your query in the
paginator_core object. Just remove dataType: 'jsonp' - Infinite Pagination example addyosmani.github.io/backbone.paginator/examples/….bentedder
Thanks. But how does the paginator modify my MySQL script so it's only pulling 20 items at a time from the database? Is that how it works? Do I need to set the LIMIT in my sql statement according the query parameter?
Vitalii Petrychuk
Oh, this is another question. I'm not a backend developer and cannot recommend you how to implement server API in that case. Please take a look at this question stackoverflow.com/questions/13872273/…