whiteoctober / Pagerfanta

Pagination for PHP.
Other
1.59k stars 2 forks source link

There's no possiblity to define "infinite" limit #201

Closed gtrias closed 8 years ago

gtrias commented 8 years ago

I'm implementing Pagerfanta on a symfony API Restfull project and it works quite well.

But I have an use case where I need to not define a limit at all, I want to return all the results to fill a select list. So in my controller, if I don't get the limit parameter, I want to apply the pagination without limit because there's a lot of logic after the pagination that expect to get a PagerFanta instance. If I don't apply pagination I would have to mess my code with a lot of if's looking if the returned object is PagerFanta or ArrayCollection...

As a workaround I defined a very high limit if there's no one defined but I found this solution a little ugly...

stof commented 8 years ago

Well, an infinite limit does not make sense for a pagination library. So this looks sensible to me to forbid it.

On a side note, allowing your API to return a non-paginated list is a bad idea IMO, as it will impact performance (and if someone really wants to build a select with a huge number of elements in it, they could load all pages)

gtrias commented 8 years ago

Well, I agree with you that infinite pagination is something weird for a pagination library. But having this it would enable you to have requests paginated and other not using the same call (sometimes you may need a non paginated response). In the other hand I agree as well that is better to handle this use case from client side.

But in my case I'm using ng-admin on the client side and I can set the limit from the select definition there, but not loading all entities without setting a limit... And I don't really wanted to create my custom reference Field Type. So set high limit is the easier solution at the moment. Unless I'm missing something about ng-admin configuration...

stof commented 8 years ago

Well, I think you should request support for loading references from a paginated list in ng-admin (maybe contributing to get the feature faster). Given that paginating lists is a good practice in APIs, I'm quite sure this has a good chance of being accepted. And in the meantime, using a very high limit is fine as a workaround. Adding support for non-paginated paginator is very ugly as well. And once added in the library, it cannot be removed again due to backward compatibility.

gtrias commented 8 years ago

Ok, so I will address this issue to ng-admin better. I close the issue. Thanks