Numeric Sort for TEXT/VARCHAR

Hey all,

i want to sort a CGRIDVIEW Column Natural/Numeric so 1,2,3,4,5… instead of 1,10,11,2…

The Problem is that there is a String then the Number and after that another string. So i need the field to be TEXT. Can i sort for another Column without showing it (so clicking on MyAttribute1 would sort for MyAttribute2?) Or even better can I force Yii to sort Numerically?


you can for sure configure CActiveDataProvider to alter default sorting rules (when user clicks on column A, results are sorted by other column). Read about configuration of ‘sort’ attributes in CActiveDataProvider.

As of sorting in yii - I do not recommend it unless there is very small set of data to be sorted. This approach needs to load all records to memory and then sort them in PHP, which is very ineffective…