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 开发者_如何学Golike 1,10,100.
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>
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);
精彩评论