I couldn't reproduce it.  Everything formats just fine with the 
grid's label function, even coming up blank with the "a" string as 
the price.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";>

  <mx:Script>
  <![CDATA[

  var data: Array = [{price: 0}, {price: 1.0}, {price: 2.00}, 
{price: 3.3}, {price: "a"}, {price: "0"} ];
   function format1()
   {
//    test1_ti.text = USDformatter.format(test1_ti.text)
    test1_ti.text = formatPrice({price: test1_ti.text}, "none");
   }

    function formatPrice( item : Object, columnName : String ):String
    {
      var formattedPrice:String = USDformatter.format(item.price);
      return formattedPrice;
    }

  ]]>
  </mx:Script>

  <mx:CurrencyFormatter id="USDformatter" precision="2" 
currencySymbol="$"
decimalSeparatorFrom="."
         decimalSeparatorTo="." useNegativeSign="true"
useThousandsSeparator="true" alignSymbol="left"/>

  <mx:VBox width="100%" height="100%">

   <mx:FormItem label="Currency Formatter:">
    <mx:TextInput id="test1_ti" focusOut="format1()" enter="format1
()" />
   </mx:FormItem>
   <mx:DataGrid dataProvider="{data}">
    <mx:columns>
        <mx:Array>
            <mx:DataGridColumn columnName="price" headerText="Price" 
labelFunction="formatPrice" />
        </mx:Array>
    </mx:columns>
   </mx:DataGrid>

  </mx:VBox>
</mx:Application>


--- In [email protected], "JesterXL" <[EMAIL PROTECTED]> wrote:
>
> This works when used with a TextInput, but does not work with a 
> labelFunction with a DataGrid.  I'm getting relaly weird results 
like 
> $"0.00" when you pass a 0 to the CurrencyFormatter.format function.
> 
> Why does this work perfectly with a TextField, but not with 
labelFunction 
> for a DataGrid?
> 
> This works:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";>
> 
>  <mx:Script>
>  <![CDATA[
> 
>   import com.mindspacexi.utils.StrUtils;
> 
>   function format1()
>   {
>    test1_ti.text = USDformatter.format(test1_ti.text)
>   }
> 
> 
>  ]]>
>  </mx:Script>
> 
>  <mx:CurrencyFormatter id="USDformatter" precision="2" 
currencySymbol="$" 
> decimalSeparatorFrom="."
>         decimalSeparatorTo="." useNegativeSign="true" 
> useThousandsSeparator="true" alignSymbol="left"/>
> 
>  <mx:VBox width="100%" height="100%">
> 
>   <mx:FormItem label="Currency Formatter:">
>    <mx:TextInput id="test1_ti" focusOut="format1()" enter="format1
()" />
>   </mx:FormItem>
> 
>  </mx:VBox>
> </mx:Application>
> 
> However, this psuedo code does not:
> 
> function formatPrice( item : Object, columnName : String ):String
> {
>  var formattedPrice:String = USDformatter.format(item.price);
>  return formattedPrice;
> }
> 
> I have confirmed through traces & debugs that item.price is in 
fact 0. 
> Strangely, even hardcoding 0 or "0" into the USDformatter.format 
function 
> still results in the $"0.00" problem.
> 
> !?!?
> 
> --JesterXL
>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to