-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
CArrayDataProvider case insensitive #990
Comments
I would even expect case-insensitive sorting to be default. Example nr4 on php.net suggests converting the array to lowercase values, as done in the solution above. |
In the end, it should be configurable. Maybe one wants to sort something containing numbers, so natural ordering would be handy. If the case insensitive algorithm is hard coded, you'll face the same problems as now: the data provider just doesn't behave the way you need it to behave. Also, modifying the class to act case-insensitive by default is a bad idea for the 1.1.x release series, because it modifies behavior. Some applications might rely on case sensitive sorting. They shouldn't break because of updating the framework. So making it configurable, with just the same sorting as now as default, seems to be the best solution to me. |
Agree with bwoester, this should be configurable. |
@BBoom Natural sorting addition should be in the separate issue, IMO. |
@resurtm Agreed, but I think making this a configurable option is a good move to allow future expanding. A first version should probably be limited to case-insensitive sorting, to speed up implementation (and also, this is the only concrete case people have reported needing). But it would be wise to implement it in such a way that other sort styles could be implemented later. In other words, not a 'caseSensitive' boolean param, but more of a 'sortingStyle' param that takes constants. |
how about setting an expression or anonymous function? |
I'm not too familiar with CArrayDataProvider source, just took a quick look. From what I see, I think the current solution with case sensitive/ insensitive flag really might be enough. If someone needs more, he can always inherit and override sortData method. However, if someone wants to do more refactoring, to make the class more flexible, I think the sortData method could be modified slightly: Sorting direction could be removed from the signature. If descending order is configured, this can be done by CArrayDataProvider by inverting the sorted array. No need to handle sort order in every implemented algorithm. |
Fixed. |
Hello
in the CArrayDataProvider class I expect the sortData() function to be case insensitive, but it is not, because it is using the php method array_multisort http://php.net/manual/en/function.array-multisort.php
I am now fixing it by creating a separate class which extends CArrayDataProvider in order to override the sortData by calling the php method strtolower() on the elements to be sorted.
(like suggested here http://www.yiiframework.com/forum/index.php/topic/17154-case-insensitive-sort/ )
Please let me know if this could be an option of the sortData in the future ?
Thanks
Yann
The text was updated successfully, but these errors were encountered: