PDA

View Full Version : Sorting a non standard variable in a Grid



rhyspaterson
15 Apr 2009, 4:45 PM
Hey team,

I have a column in one of my grids that contain variables like such:

1:8.256
1:5.233
1:1.476
1:0.53
1:0.001
ect

Now sorting this using the default sort type is fine (i.e, it works). However! I run into an issue when i get records like such:

1:22.125

As it will be sorted like such:

1:8.256
1:5.233
1:22.125
1:1.476
1:0.53
1:0.001

When obviously it is a larger number. Now i assume there are two ways to resolve this.

One, i can create a custom sort function (as none of the predefined functions can help here). I've had a look around, and telling it to use the custom function doesn't look hard (sortType: 'myCustomFunction') - writing it however, looks nigh on impossible to me... maybe i'm missing something though. The custom sort function in the Grid FAQ (http://extjs.com/learn/Ext_FAQ_Grid#Sorting_issues) doesn't seem to be able to do what i want.

Two, i change the record before i read it in. I.e, from now on, just store it without the '1:' in my XML file, and then, once i have sorted the data, i insert '1:' in front of each record in the column. This sounds a bit intensive however and i'm not sure what effect this will have on performance.

If possible, could someone point me to somewhere that can show me how to create basic custom sort functions? Any tips for the current issue would be much appreciated too..

Thanks!