RKCY
RKCY

Reputation: 4135

Sorting in Advanced Datagrid

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.

Upvotes: 0

Views: 802

Answers (2)

ZackBeNimble
ZackBeNimble

Reputation: 549

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);

Upvotes: 0

invertedSpear
invertedSpear

Reputation: 11054

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>

Upvotes: 1

Related Questions