Reputation: 4246
I'm trying to format some numbers in a column of a DataGrid. I'm getting an error in my simplified test program below when I run it. All the examples I've seen so far have column data that are strings. Is there a way to do it using numbers? How to modify the code below to format the checking
values?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
[Bindable]
public var checking:Array = new Array(1000000.2222, 0, 1000);
private function myLabelFunction(item:Array, column:DataGridColumn):String {
var result:String;
result = myFormatter.format(item);
return result;
}
]]>
</fx:Script>
<fx:Declarations>
<s:NumberFormatter id="myFormatter"
fractionalDigits="2"
decimalSeparator="."
groupingSeparator=","
useGrouping="true"
negativeNumberFormat="0"
/>
</fx:Declarations>
<mx:DataGrid id="dg1" dataProvider="{checking}" >
<mx:columns>
<mx:DataGridColumn dataField="checking" headerText="Checking"
labelFunction="myLabelFunction" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
Upvotes: 2
Views: 4957
Reputation: 1
In case of object you must use/No caso de objeto, deve-se usar:
private function myLabelFunction(item:Object, column:GridColumn):String {
var result:String;
result = myFormatter.format(item[column.dataField]);
return result;
}
Upvotes: 0
Reputation: 6597
While the label function will certainly work -- I usually prefer an ItemRenderer for things like this. You override the render function and then you can display whatever it is in the grid view "box" however you like.
A decent example is here. Scroll down about 1/4 the way down for a DataGrid example.
Upvotes: 1
Reputation: 7294
Change filter function signature (item
should be Object
)
private function myLabelFunction(item:Object, column:DataGridColumn):String
Remove dataField="checking"
from column.
Upvotes: 2