emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.45k stars 4.21k forks source link

Request to add Ember.PaginationSupport to the ember core #1386

Closed toranb closed 11 years ago

toranb commented 12 years ago

I've been playing with ember off and on the last month or so and it seems one of the basic features missing that would help make any web developer productive from day one is support for pagination.

I threw this very question out to the stackoverflow community and it looks like one of the ember contributors @tchak already has a well written mixin for pagination.

https://gist.github.com/1559628

Would it be possible to roll this into a release in the future?

dmathieu commented 12 years ago

All existing mixins don't need to be included into ember core. You can very easily add this file into your asset pipeline and use it just as is. Just as there are a few open source mixins here and there. Take a look at what there is at emberjs-addons for example.

I don't think this really fits into ember core.

tchak commented 12 years ago

agreed, not in the current state at last...

But ember-data should definitely support pagination "out of the box", maybe through some kind of sparse array

dmathieu commented 12 years ago

The way I see it, the ember-data pagination should allow retrieving batches of records to avoid making one very big and long query.

toranb commented 12 years ago

Agreed on the point that "not every mixin / idea" should be in the core but I see the philosophy of ember as "if 90% of developers will need to write this by hand anyway" -why not give them tested / well written code that does just this. I feel the Ember.SortableMixin must have been a similar story (everyone needs to sort / paginate / search the ArrayController so why not provide support out of the box)

tchak commented 12 years ago

@toranb I agree with you, but the functionality we put in core should be more generic. I would be in favor of ActiveRecord-like methods limit and offset on RecordArray. We would need to find a way to chain them with other methods though.

toranb commented 12 years ago

Can't say I disagree completely but I'm having a hard time selling ember (the best mvc framework to date IMHO) to my team when other frameworks get you so much "CRUD stuff" out of the box and I'm left saying "but we just need to add this mixin ...". I understand that Ember is about building ambitious web apps but I've found that learning a framework this size takes time and getting to the point where you need it can be painful when you are writing / copying code that is essential to just about any web app (CRUD or not). If nothing else thanks for the discussion (and the awesome mixin you wrote -it will be used on my personal stuff without question!)

wagenet commented 12 years ago

@toranb For the most part, the CRUD stuff other frameworks is barely a skeleton, especially in Backbone's case. Don't look at it as a list of checkboxes, look at the actual code and what it really does for you. As to whether or not we include a pagination mixin, I think it depends on the percentage of apps that will have a need for it. If the vast majority would make use of it, then we should include it. If not, it should be a separate addon.

ahawkins commented 11 years ago

@wagenet you can probably close this one.

wildchild commented 11 years ago

I think that lack of pagination in ember will frustrate average emberjs users. It's essential. Ember-data could have support for offset and limit options in finders and also support meta objects https://github.com/rails-api/active_model_serializers/commit/6780cd3df5b14d85a7fd032af961853a9eb7c2cf in JSON responses.

Thus response will be:

{ "meta": { "total": 1000 }, "people": [{"name": "John Doe"}, {"name": "Jane Doe"}] }

App.Person.all(2, 5) // offset and limit can return special proxy with total property from meta object along with first class citizens like isLoaded, etc.

It's nothing really matters how, by plugin or mainline. Pagination just should be.

darthdeus commented 11 years ago

+1 for adding this to the core. It's one of those things which you really want in most of the apps.

synthresin commented 11 years ago

+1 Pagination is very essential functionality

brennanmceachran commented 11 years ago

Either +1 or a guide how to handroll w/ ember seeing as it's so common

toranb commented 11 years ago

If anyone is looking for an up to date RC1 friendly pagination example, I just got this working (back button support with the router included) https://github.com/toranb/ember-django-rest

loadx commented 11 years ago

@toranb This is a client-side example and does not take into account meta so I'd say at this level this functionality can live as a stand-alone mixin. Nice work on the routes btw, the sort route is definitely something useful not sure if bookmarking a particular page is, though at least it affords history functionality.

What we do need support for is obtaining the meta information (#124) and paginating by things like 'limit' etc.

toranb commented 11 years ago

@loadx agreed -this solution doesn't scale up very well. But doesn't a true server side pagination solution depend more on ember-data than the mvc part of ember itself?

loadx commented 11 years ago

Absolutely, which is why I should of pointed out that 124 was an ember-data ticket. (https://github.com/emberjs/data/issues/124)

Cheers.

devilankur18 commented 11 years ago

+1

kristianmandrup commented 11 years ago

+1

vgantchev commented 11 years ago

+1

sbsurf commented 11 years ago

+10

stefanpenner commented 11 years ago

my vote is pagination as an addon: http://emberaddons.com/

ahawkins commented 11 years ago

I'll put together a JSBin showing how to paginate. I agree as an add-on. I think people will be happy if we at least show them how to do it.

On Jun 28, 2013, at 1:43 PM, Stefan Penner notifications@github.com wrote:

my vote is pagination as an addon: http://emberaddons.com/

— Reply to this email directly or view it on GitHub.

sbsurf commented 11 years ago

Ideally, it would also show a way to make requests to the back-end one page at a time, as opposed to loading the whole dataset and paging through in on the client only.

toranb commented 11 years ago

For those who want to see an example of pagination with ember, the jsfiddle below shows a pure client side pagination mixin and how to use it with a vanilla ArrayController.

http://jsfiddle.net/ZUEzm/2/

The full blown project is on github and the pagination mixin is unit tested with jasmine for those interested

https://github.com/toranb/ember-pagination-example

About the issue itself, I've changed my stance and don't think this should be in the core of ember.js. I think the core of ember should be very focused and the pagination mixin makes for a great add on (thanks to @stefanpenner for the link above).