Accessibility
Adobe
Sign in My orders My Adobe

Flex Documentation

Formatting data in a List-based control


Table of Contents

  1. Displaying images in a List-based control
  2. Validating data in a List-based control
  3. Formatting data in a List-based control
  4. Creating a DataGrid header renderer
  5. Creating a Tree row renderer

Just as you can format data in other types of controls, you can format data in the cells of List-based controls.You can apply a formatter to a List-based control without creating a custom cell renderer.

The following figure shows a DataGrid column that uses a NumberFormatter formatter to round the numbers in the second column:

Formatted cell content example.

To apply a data formatter to the cells of a List-based control, you do the following:

  • Declare a formatter tag in MXML; for example:
    <mx:NumberFormatter id="FORMATTER" precision="1"/>
    
  • Specify an ActionScript function as the value of a labelFunction property of a List control or DataGridColumn; for example:
    <mx:DataGridColumn columnName="age" headerText="age-Formatter" labelFunction="formatAge"/
    
  • Call the formatter's format() method in the ActionScript function specified in the labelFunction property; for example:
  function formatAge(item){
    return FORMATTER.format(item.age);


}