Instances of class Date support < and > operators. Your
sortCompareFunction should be comparing the saledt field in two data
items:

<mx:DataGridColumn ... sortCompareFunction="saledtCompareFunction" ...
/>

private function saledtCompareFunction(item1:Object, item2:Object):int
{
if (item1.saledt > item2.saledt )
{
return 1;
}
else if( item1.saledt < item2.saledt )
{
return -1;
}
else
{
return 0;
}
}

- Gordon

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of michael_ramirez44
Sent: Friday, January 19, 2007 9:04 AM
To: [email protected]
Subject: [flexcoders] Re: Sorting Dates in Datagrid

 

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Steve Moore" <[EMAIL PROTECTED]> wrote:
>
> I've got a datagrid binded to an ArrayCollection returned from a
> ColdFusion query. One of the columns is a date field that I'm using 
a
> labelFunction to format in mm/dd/yyyy format. From reading various 
posts
> I see that I need to code a sortCompareFunction to allow proper 
sorting
> on this column. However I haven't found any code to do this. Does 
anyone
> have such code? Below are the basics of my flex app.
> 
> 
> <mx:DataGrid x="10" id="dgSales" dataProvider="{salesResult}" 
top="0"
> bottom="10">
> <mx:DataGridColumn headerText="Sale Date" labelFunction="formatDate"
> width="80"/>
> 
> public function formatDate(item:Object, 
column:DataGridColumn):String
> {
> if(item.saledt!=null) {
> return dateFormat.format(item.saledt);
> } else {
> return '';
> }
> }
> 
> 
> 
> Steve Moore
> Larimer County Web Administrator
> (970) 498-5049
> [EMAIL PROTECTED]
> www.larimer.org
>
<mx:DataGridColumn headerText="Sale Date" labelFunction="formatDate"> 
width="80" sortCompareFunction="sortColumnNumber"/>

private function sortColumnNumber( x:Object, y:Object):int
{
if( num1 > num2 )
{
return 1;
}
else if( num1 < num2 )
{
return -1;
}
else
{
return 0;
}
}

 

Reply via email to