This content has been marked as final. Show 5 replies
if dataGrid's dataprovider is ArayCollection I would use built in Sort feature,
you will need : Sort class SortField class and compareFunction
I think I have some example at home will post tonight
from SDK :
var col:ICollectionView = new ArrayCollection();
// In the real world, the collection would have more than one item.
// Create the Sort instance.
var sort:Sort = new Sort();
// Set the sort field; sort on the last name first, first name second.
// Both fields are case-insensitive.
sort.fields = [new SortField("last",true), new SortField("first",true)];
// Assign the Sort object to the view.
col.sort = sort;
// Apply the sort to the collection.
Thanks for the quick reply.
Couple questions . ..
How does this affect my data grid when someone clicks on a column heading.
Am I better off converting the data once from string to a date and letting the d/grid handle the sorting itself or converting it in the sort routine?
you dont have to convert anything just implement function and asign it to Sort object's "compareFunction" property
The compare function must have the following signature:
function [name](a:Object, b:Object, fields:Array=null):int
This function must return the following
* -1, if a should appear before b in the sorted sequence
* 0, if a equals b
* 1, if a should appear after b in the sorted sequence
inside that function you might need a tmp conversion but overall that should be it
for example (function can look like this :
if a===b) return 0;
if(myStringToDateConvertor(a) > myStringToDateConvertor(m) ) return 1;
if(myStringToDateConvertor(a) < myStringToDateConvertor(m) ) return -1;
(remember sortField also has has compareFunction property but you dont need that one).
Could someone provide a detailed example with code.
Appreciate your help.