Ember.js and Pagination

ember.js, javascript, pagination

Solution

So I turned towards creating a mixin that looks a bit like this

App.PaginationHelper = Em.Mixin.create({
    pageSize: 10,
    totalLines: 20,
    rangeStart: 1,
    rangeStop: function () {
        var rangeStop = get(this, 'rangeStart') + get(this, 'pageSize') - 1;
        totalLines = get(this, 'totalLines');
        if (rangeStop < totalLines) {
            return rangeStop;
        }
        return totalLines;
    }.property(),

    currentPage: function () {
        return get(this, 'rangeStop') / get(this, 'pageSize');
    }.property(),

    totalPages: function () {
        return Math.ceil(get(this, 'totalLines') / get(this, 'pageSize'));
    }.property(),
[...]

And so on, then created a separate view for it, as this way I can reuse it, and even reuse it many times on a single page, by creating a container div with a unique id to append each instantiation of the view to append to.

So I can repeat the next lines with new variables, but reuse the template by keeping the templateName the same.

var firstCaseOfPaginationViews = Em.View.create({
    templateName: 'pagination'
    [...]
});

firstCaseOfPaginationViews.appendTo('#transaction_pagination');

And now, the mixin can now be simply included to any controller that I need pagination for. I'm hoping this is the correct way of doing things in Ember, it seems like this will be the way that I'll adopt until I refactor and revisit at a later date.

Problem

So the issue is that, I'm trying to load quite a bit of entries from a JSON data file (about 5000 entries), into table rows, and I was wondering what would be the best way to handle pagination. I'm aware of jPages, and other plug-ins, but as I'm fairly new to Ember.js, I wanted to know if there was an Ember way of making this work. I can kinda think of passing the total amount of the entries, manually loop a render through a set amount, but I don't think that would be very portable to other areas where I would need pagination. Should I look into Routing?

Original source