If it recognizes the coumn as number, it's should try a numeric sort,
but if you got a few empty or mismatched data points it will fail to
text mode. To ensure a numeric sort you'll need to add somthing like
this:
<mx:DataGridColumn sortCompareFunction="numericSort" />
public function numericSort(obj1:Object, obj2:Object):Number{
if(isNaN(Number(obj1.int1))){
return -1;
}else if(isNaN(Number(obj2.int1))){
return 1;
}
if(Number(obj1.int1) < Number(obj2.int1)){
return -1;
}else if(Number(obj2.int1) < Number(obj1.int1)){
return 1;
}else{
return 0;
}
}
You can actually add to the isNaN() portion regular text sorting if
you feel up to it.
On Sun, May 25, 2008 at 1:17 PM, Tung Lee <[EMAIL PROTECTED]> wrote:
> I have a datagrid that's feed by a XML doc through HTTPService.
> Some of the columns that's displaying shows +/- integers.
> When user click on the column header to sort those +/- integers, Flash sorts
> like text instead of integers.
>
> for example, the numbers are 1, -1, -3, 2, 5, 0, -2, -4
> (correct) it should be sort like this: -4, -3, -2, -1, 0, 1, 2, 5
> (no correct) however, it end up like this: -1, -2, -3, -4, 0, 1, 2, 5
>
> For my datagrid I use DataGridColumn elements and datafield to fill the
> datagrid.
> Following are an example of my datagrid code.
>
>
> <mx:DataGrid id="dgLB" itemClick="{lbChangeFunction()}">
> <mx:columns>
> <mx:DataGridColumn dataField="Int1" width="35"
> textAlign="center" paddingLeft="1" paddingRight="1"/>
> <mx:DataGridColumn dataField="Int2" width="35"
> textAlign="center" paddingLeft="1" paddingRight="1"/>
> </mx:columns>
> </mx:DataGrid>
>
>
> Thanks for any help.
>
> Tung Lee
>
> -------------------------------------------------------------
> To unsubscribe from this list, simply email the list with unsubscribe in the
> subject line
>
> For more info, see http://www.affug.com
> Archive @ http://www.mail-archive.com/discussion%40affug.com/
> List hosted by FusionLink
> -------------------------------------------------------------
--
Darin Kohles
RIA Developer
-------------------------------------------------------------
To unsubscribe from this list, simply email the list with unsubscribe in the
subject line
For more info, see http://www.affug.com
Archive @ http://www.mail-archive.com/discussion%40affug.com/
List hosted by http://www.fusionlink.com
-------------------------------------------------------------