Howdy,
Pretty new to AS3, but thought I'd see if you can help me out here.
I have a datagrid with some numeric columns. I created an item itemRenderer to
add commas to those columns. But now the columns won't sort numerically. I
saw some code that I have attached, the problem is, the code references the
columns by name "testvalue." and I need it to work generically, no matter what
column I am sorting.
Help?
<?xml version=?1.0? encoding=?utf-8??>
<mx:Application xmlns:mx=?
http://www.adobe.com/2006/mxml? layout=?absolute?>
<mx:XMLList id=?testdata?>
<testdata> <name>a</name> <testvalue>1</testvalue> </testdata>
<testdata> <name>aa</name> <testvalue>11</testvalue> </testdata>
<testdata> <name>ab</name> <testvalue>12</testvalue> </testdata>
<testdata> <name>b</name> <testvalue>2</testvalue> </testdata>
<testdata> <name>ba</name> <testvalue>21</testvalue> </testdata>
<testdata> <name>bb</name> <testvalue>22</testvalue> </testdata>
<testdata> <name>c</name> <testvalue>3</testvalue> </testdata>
<testdata> <name>d</name> <testvalue>4</testvalue> </testdata>
<testdata> <name>e</name> <testvalue>5</testvalue> </testdata>
<testdata> <name>f</name> <testvalue>6</testvalue> </testdata>
<testdata> <name>g</name> <testvalue>7</testvalue> </testdata>
</mx:XMLList>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.SortField;
import mx.collections.Sort;
private function sortNumeric(obj1:Object, obj2:Object):int {
var value1:Number = (obj1.testvalue == '' || obj1.testvalue == null) ? null :
new Number(obj1.testvalue);
var value2:Number = (obj2.testvalue == '' || obj2.testvalue == null) ? null :
new Number(obj2.testvalue);
if (value1 < value2) {
return -1;
} else if (value1 > value2) {
return 1;
} else {
return 0;
}
}
]]>
</mx:Script>
<mx

ataGrid x=?10? y=?10? dataProvider=?{testdata}? id=?dgTest? width=?400?
height=?300?>
<mx:columns>
<mx

ataGridColumn headerText=?text? dataField=?name? />
<mx

ataGridColumn headerText=?number as text? dataField=?testvalue? />
<mx

ataGridColumn headerText=?number as number? dataField=?testvalue?
sortCompareFunction=?sortNumeric? />
</mx:columns>
</mx

ataGrid>
</mx:Application>