-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort custom field enum #819
Comments
How do you expect the sorting to work? |
I don't know, it works in repositories and Easyadmin i don't know why it doesn't work with Paginator |
I mean: what's your current expectation, and what's your actual result instead? |
The difference between a doctrine query and KnpPaginator is that when you use addOrderBy it orders the enum according to the order of the possible values of the enum that has been defined in the type in the database. Whereas KnpPaginator uses a usort(). We could add this piece of code in the sortFunction method of the Knp\Component\Pager\Event\Subscriber\Sortable\ArraySubscriber
This works in the case where the Enum typed field uses a PHP Enum: as explained in this KNPLabs article. |
Why don't you use native Doctrine enums? |
By the way, ArraySubscriber is used when you sort arrays. If you sort a query, QuerySubscriber is used instead |
Because with native Doctrine enums, the enums are sorted by alphabetical order
Thank you it's working with the QuerySubscriber, we were using the Collection ( Are there any other differences between passing a query or a collection of objects to the paginator? |
You must pass the Query (or the QueryBuilder). |
Feature Request
Summary
I have a custom field in my entity that is converted to an enum field in my database. I did this because dbal enum allows to sort this field automatically in custom order.
This works with EasyAdmin crud controller and custom request in repositories, but not with paginator.
Is it a bug or a new feature to implement ?
Link to custom type doctrine to make enum field
The text was updated successfully, but these errors were encountered: