views:

56

answers:

2

Hi,

I have a Advanced Datagrid with sorting. I think it is string sorting by default. But i need the sorting in number. How can i achieve the number sorting.

for example: i have row numbers like 1 to 100 . i need number sorting like 1,10,100.

thanks, ravi

+1  A: 

in your advancedDataGridColumn add a sortCompareFunction:

<mx:AdvancedDataGridColumn sortCompareFunction="NumberSorter" 
sortDescending="true" dataField="number" headerText="Formal Name" width="280"/>  

Add the function somewhere in your scripts

<mx:Script>
    <![CDATA[

        import mx.utils.ObjectUtil
        public function NumberSorter(itemA:Object, itemB:Object):int{
        return ObjectUtil.numericCompare(itemA.number, itemB.number);
    }

    ]]>
</mx:Script>
invertedSpear
A: 

If your underlying data source is a simple Array of numbers, you can simply call sort():

myArray.sort(Array.NUMERIC);

If your numbers are in a specific field for each array entry object, you could instead use sortOn():

myArray.sortOn("rowNumberField", Array.NUMERIC);
ZackBeNimble