6

At the moment I'm pointless how do achieve pagination with ember-data. I found out, that i can return 'meta' property in response and ember-data does not throw an error. But I just don't know how to access it, nor what is intended purpose of this property.

The few examples on internet assume that i have whole collection already loaded to ember, or they do little trick and do infinite scroll, which does'nt require information about page count.

I think that loading all records it's ok if I would have < 1k of them, but sometimes I'll be dealing with massive amounts of data (let's say apache logs). What then?

So basically I'm at the point in which I would like to use ember and ember-data to build my first real-life application, but I just think that it is not a good idea.

Ok, so anybody has any idea how to solve this basic, yet complicated, problem? :)

ahmacleod
  • 4,280
  • 19
  • 43
Kamil Biela
  • 706
  • 1
  • 6
  • 13
  • Are you using RC1 and ember-data rev 11? Also what adapter are you using with it? What server backend do you have? Do you need each page to respect history and the back button? – Toran Billups Mar 02 '13 at 18:09
  • Take a look at [this question](http://stackoverflow.com/questions/13699796/ember-data-loading-hasmany-association-on-demand/14532845#14532845). There is some [ongoing discussion](https://github.com/emberjs/data/issues/666) on the github tracker as well. – ahmacleod Mar 03 '13 at 03:41
  • @Toran Billups: all latest taken from github repos. – Kamil Biela Mar 03 '13 at 12:30
  • as for backend: it's simple solution based on [silex](http://silex.sensiolabs.org/). History and back button would be nice. – Kamil Biela Mar 03 '13 at 12:55

1 Answers1

1

Ok, so here are some ideas to get you started.

First, you have to start with a route and take an page number as a dynamic parameter.

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

Then as I have no experience with Silex, you need to support some kind of server side parameters that could be used for pagination. For example offset and limit where first means how many records you want to skip and second how many record you want in select from there. Ideally you should implement them as query parameters like ?offset=0&limit=10.

Then you just 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  });
    }
});

You can then start doing some more magic and create your items per page parameter or validate the page number by fetching number of all records in advance.

Myslik
  • 1,178
  • 6
  • 14
  • thanks for the answer, but I switched to angular.js. In my opinion it's much better than Ember.js - everything is nicely testable with karma runner and jasmine. – Kamil Biela Apr 24 '13 at 08:37