2 Replies Latest reply on Aug 21, 2007 11:56 AM by Handycam

    Formatter  in a data grid

    Handycam Level 1
      I've got a custom formatter. It works fine when applied to a text field:

      <comp:FractionFormatter id="makeFraction" myNumber="{rg0.data.@qty}"/>
      <mx:TextInput id="myTI"/>
      <mx:TextArea text="Formatted string is {makeFraction.format(myTI.text)}"/>

      But fails when I try to use it in a data grid. I assume my syntax is wrong here somewhere:

      <mx:DataGridColumn id="q" dataField="{makeFraction.format(data.@qty)}" width="35" wordWrap="true"/>

      The failure says "unknown value 'qty'". I'd love to get this working, it would save a lot of other code.
        • 1. Re: Formatter  in a data grid
          flexPro
          You'll want to use labelFunction. Try this:

          <mx:DataGridColumn id="q" dataField="data.@qty" width="35" wordWrap="true" labelFunction="formatQty" />

          /* This method signature is required for DataGrid labelFunctions */
          public static function formatQty(data:Object, col:DataGridColumn):String
          {
          /* data is the data object for the row, not the quantity itself */
          return makeFraction.format(data.@qty);
          }

          I haven't compiled this, so there may be a typo, but the general idea is right.
          • 2. Re: Formatter  in a data grid
            Handycam Level 1
            Thanks, but unfortunately the compile fails with:
            Error: Access of undefined property makeFraction.

            Flagging the line:
            public static function formatQty(data:Object, col:DataGridColumn):String