-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
DateTime sortable #409
Comments
👍 I also have this issue |
Found out that is only occurs when you pass an already hydrated array with objects to the sortable. |
Ah, thanks for your answer. Effectively, I give an hydrated array via the following :
So, for me, giving the querybuilder means re-build what I can have by using the repository, which is, for me, and if I understand well, NOT what should be done as "good practice". |
Well that depends on how you define the return type in your repository function.
Would be an approach without giving up on repository functionality |
Thanks for your code! |
I understand your view of code.
As I see it, option 1 has the least impact. |
Same problem with sorting by DateTime field type.
$users = $this->getDoctrine()->getRepository('DashboardBundle:User')->findAll();
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$users,
$request->query->getInt('page', 1),
10
); REQUEST:
RESPONSE:
|
Inddeed, we can't sort on \DateTime. I think this PR on knp-components should solve your issue. I ping you when it's ready. |
Still, why would you want to hydrate everything from the database and then put it in the paginator. It might work for small tables but those can get large too you know. The only reason is when you would use a js datatable of some sort for this setup to be efficient. In other cases, let the paginator build your query and apply the offset and size. Then, datetime sorting won't be an issue anymore aswell. |
Because the paginator paginates everything, wherever it comes from a database or not. Thus, I don't understand this point: I (and other maintainers) never recommended to paginates only array. And I can find at least another example where array paginator is useful: paginating items coming from a SOAP response (you can forget about iterators and generators). Also you noted yourself that sorting on |
I'm not saying it shouldn't be supported. Only when working with large datasets, hydrating everything (mostly into entity objects) is not cost efficient nor time efficient for your application and heavy on the database. But I think this more of a "how do you implement your code" topic :) |
@ricohumme As I said, I agree with you, but it forces us to re-write what's "built-in", but I think you're right and I should work in this direction.
It should lowerizes the load on the server, isn't it? |
It should. However, I'm not to keen myself on this topic but maybe this could help a little https://stackoverflow.com/questions/38093196/symfony-3-apcu-php7 |
@Laurent3170 In your case I agree with @ricohumme you should rely on doctrine paginator rather than paginating the whole transaction set. It will be more efficient. Beside this point, could you update |
@NiR- Yes I confirm that updating files in KnpLabs/knp-components#159 makes the array sortable on date! Concerning this issue, should it be closed? As till the PR is not present in a superior version of knp-components, the sortable array won't work. |
@Laurent3170 We'll release a new version of knp-components soon. So I consider this PR solved, since it wasn't really related to this repo, the encountered bug as been solved and you choose the most efficient way of sorting for your use case :) |
And thanks for your work for having made the array sortable on a date! |
Hi,
according to @clytemnestra in KnpLabs/knp-components#129, it seems that it's NOT possible to sort based on a
DateTime
?Because, I am trying to paginate with a
DateTime
object but I receive the following errorWarning: strtolower() expects parameter 1 to be string, object given, full log is CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: strtolower() expects parameter 1 to be string, object given" at /.../vendor/knplabs/knp-components/src/Knp/Component/Pager/Event/Subscriber/Sortable/ArraySubscriber.php line 61
I give
a.dateTransaction
to the query which is the name of the field in the entity.So, is it really impossible to sort on a DateTime ?
The text was updated successfully, but these errors were encountered: