In theory, you don't want a sortCompareFunction for this.  You want to
sort the underlying numeric data and its formatted strings should be in
the right order and the sort will be much faster.

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of valdhor
Sent: Monday, June 02, 2008 10:32 AM
To: [email protected]
Subject: [flexcoders] Re: Flex 3 - Help sorting formatted data in
datagrid

 

You need a sortCompareFunction:

In your script area add...

import mx.utils.ObjectUtil;

Then add the following function...

private function myCompareFunc(itemA:Object, itemB:Object):int
{
    return ObjectUtil.numericCompare(itemA.Quoted_Total,
itemB.Quoted_Total);
}

Now change your DataGridColumn component to...

<mx:DataGridColumn headerText="Formatted Total (Flex will now sort)"
sortCompareFunction="myCompareFunc">

That should do it.


HTH.



--- In [email protected], "Kevin Ford" <[EMAIL PROTECTED]> wrote:
>
> I need someone to help verify a problem I'm running into and perhaps
> recommend a solution. What I'm trying to do should be very simple: I
want to
> allow users to sort a datagrid column! containing data formatted using
a
> CurrencyFormatter. The problem I'm finding is that sorting (by
clicking the
> column header) works fine on raw numbers, but trying to do the same on
> formatted numbers doesn't do anything. I'm using Flex Builder 3, but
have
> tried this using both the Flex 2 and Flex 3 compilers on two different
> systems. Initially I was trying this using an AdvancedDataGrid, but
found
> the same problem using just a basic DataGrid.
> 
> Attached is a simple mxml file that fully demonstrates my problem. I
also
> have a bug logged with
Adobe(http://bugs.adobe.com/jira/browse/FLEXDMV-1769)
> that I'd love to cancel. Am I missing something? Am I just going to
have to
> define my own sort function?
> 
> Thanks!
> Kevin
>

 

Reply via email to