I have a problem with displaying Chart of Accounts of my client. They used decimal notation for the code such as, 1.1.1, 1.1.2 … , 1.1.10, 1.1.11, 1.1.12 and so on sometimes the decimal happened in the middle, 220.127.116.11, 18.104.22.168, … 22.214.171.124, 126.96.36.199
Using default sort on CGridView will result in 1.1.10 comes after 1.1.2 before 1.1.2, also 188.8.131.52 comes after 184.108.40.206 before 220.127.116.11. It become unsorted…
In PHP I learn that natsort can be used to solve this problem, but I don’t know how to implement this using yii way in my gridview.
Yes, I am on MySql. Which one from the link to be tried? I just confused when reading it.
What I did was, to compose a CArrayDataProvider by first retrieved the data then sort it in php using natsort then compose the array. To me it was not so efficient. especially since I need to make one sql call just to create the order in addition to compose the order array result.
sort by primary key did not work since COA can be added in the future so it becomes invalid.
using order field will be the most easiest way to do but I do not want to put a lot of effort just for sorting the result ;(
I were referring to the second answer (the one with 41 pts, un der the “accepted” answer. The hyperlink anchor should’ve actually pointed you there). This is actually pretty much the definition of a lexicographic (i.e. “natural”) order being brought to MySQL.
Are you using active records at any point? Using the solution from SO, you could at least use a CSqlDataProvider.