Ember.js rest api pagination

At the moment, I am pointless about how to achieve pagination using ember data. I found out that I can return the "meta" property in response, and the ember-data does not throw an error. But I just don’t know how to access it, nor what is intended for this property.

A few examples on the Internet suggest that I have a whole collection already loaded into ember, or they do a little trick and do endless scrolling that does not require information on the number of pages.

I think that loading all entries into this is normal if I had <1k of them, but sometimes I will deal with a huge amount of data (say, apache logs). What then?

So basically I'm at a point where I would like to use ember and ember-data to create my first application in real life, but I just think this is not a good idea.

Okay, so does anyone know how to solve this basic but complex problem? :)

+6
source share
1 answer

So, here are some ideas to get you started.

First you must start with the route and take the page number as a dynamic parameter.

this.resource('posts', { path: '/posts/:page' }; 

Then, since I have no experience with Silex, you need to support some server-side options that you can use to paginate. For example, offset and limit , where first means how many records you want to skip, and then specify how many records you want to select. Ideally, you should implement them as query parameters, such as ?offset=0&limit=10 .

Then you simply implement your table route as follows:

 App.TableRoute = Ember.Route.extend({ model: function (params) { return App.Post.find({ offset: (params.page - 1) * 10, limit: 10 }); } }); 

Then you can start to do even more magic and create your own parameter on the page or check the page number, having previously scored the number of all records.

+1
source

All Articles