PDA

View Full Version : Custom sorting of objects using extjs default sortring



Developer1729
14 Jan 2010, 1:11 AM
Instead of just values in my data i use objects like this:

{dataArr:[point1, point2], style: 'myStyle'}

And i want to sort by point1, actually my render function returns value.dataArr[0].
AFAIK i can use custom sort by overriding

sortType: function(value){}
But the question is how can use extjs default sorting not for value, but for
value.dataArr[0]?

Condor
14 Jan 2010, 1:18 AM
You already answered your own question:

sortType: function(value){
return value.dataArr[0];
}

Another option would be to extract the values as separate fields.

Developer1729
14 Jan 2010, 1:26 AM
Thanks, works great.

Developer1729
14 Jan 2010, 5:13 AM
Now the problem is that everything is sorted as a string...
How can i sort it as a date or integer?

P.S. I don't define type in fields, because my data isn't of simple type - it's always object like this:
{dataArr:[date, integer], style: 'myStyle'}

jax_meister
14 Jan 2010, 7:20 AM
I'm not sure if it is the best way to accomplish it but I'm doing this.


sortType: function(value){
return Number(value.dataArr[0]);
}

Developer1729
14 Jan 2010, 7:23 AM
Solved already by parsing into Date and float.
Anyway thanks.

By the way, does anyone know how can i add button to grid's column header?