In this exercise you will use multiple methods to apply item
editors and item renderers to a DataGrid control. One such example is
shown in Figure 1.

Figure 1. Apply a NumericStepper component as a drop-in item editor for a DataGrid column.
In this exercise, you will learn how to:
In order to complete this tutorial, you need the following software and files:
In this section, you will use a NumericStepper as a
drop-in item editor to change the employee evaluation score.
UI components comment, locate the DataGrid control. Make the DataGrid control editable by assigning true as the editable value:
<mx:DataGrid dataProvider="{employeeList}"
editable="true">
<mx:columns>
<mx:DataGridColumn dataField="lastName"
headerText="Last Name"/>
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation"/>
</mx:columns>
</mx:DataGrid>
To the DataGridColumn control that is assigned to display the lastName data field of
the employee data, assign false as the editable value:
<mx:DataGrid dataProvider="{employeeList}"
editable="true">
<mx:columns>
<mx:DataGridColumn dataField="lastName"
headerText="Last Name"
editable="false"/>
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation Score"/>
</mx:columns>
</mx:DataGrid>
To make a DataGrid column editable, you must first make
the entire DataGrid editable, and then turn off the editable option
for the fields that should not be editable.
To the DataGridColumn control that displays the employee’s evaluation score, assign mx.controls.NumericStepper as the itemEditor class:
<mx:DataGrid dataProvider="{employeeList}"
editable="true">
<mx:columns>
<mx:DataGridColumn dataField="lastName"
headerText="Last Name"
editable="false"/>
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation Score"
itemEditor="mx.controls.NumericStepper"/>
</mx:columns>
</mx:DataGrid>
To the same DataGridColumn control, assign value as the editorDataField value:
...
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation Score"
itemEditor="mx.controls.NumericStepper"
editorDataField="value"/>
...
The editorDataField property references the property
of the itemEditor class that should be used in this column display. For example, to display the
value of a text field, the itemEditor property value would be mx.controls.TextInput and the editorDataField would be text. In this example, you are displaying the value property of the NumericStepper control.
Click on an employee evaluation score.
You should see the NumericStepper control
appear and let you change the employee evaluation score (see Figure 2).

Figure 2. Click the employees evaluation score to see the NumericStepper control appear.
In the previous section, the NumericStepper control
was only displayed when the user clicked a particular record in the column.
This is because the control was applied only as an item editor. In this
section, you will apply the control as both an item editor and a renderer.
DataGrid control. To the DataGridColumn control, change the itemEditor property to an itemRenderer property:
<mx:DataGrid dataProvider="{employeeList}"
editable="true">
<mx:columns>
<mx:DataGridColumn dataField="lastName"
headerText="Last Name"
editable="false"/>
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation"
itemRenderer="mx.controls.NumericStepper"
editorDataField="value"/>
</mx:columns>
</mx:DataGrid>
To the same DataGridColumn control, assign true as the renderIsEditor property:
...
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation"
itemRenderer="mx.controls.NumericStepper"
editorDataField="value"
rendererIsEditor="true"/>
Save the file and run the application.
You should see the Evaluation column has the NumericStepper control applied to each evaluation score (see Figure 3).

Figure 3. Run the application to see the NumericStepper control applied to every item in the Evaluation column.
In the previous sections, you applied the NumericStepper control as drop-in item editors and item renderers by simply referring to the
class name in the itemEditor or itemRenderer properties. This limits your ability to specify any additional properties to
that control.
In this section, you will apply the NumericStepper control
to the DataGrid control column as an inline item renderer. This will allow you to put limits on
the values that can be placed into the control.
DataGrid control.DataGridColumn control that creates the Evaluation column, delete the item renderer and rendererIsEditor properties and values. Convert the DataGridColumn tag into a tag block:
<mx:DataGrid dataProvider="{employeeList}"
editable="true">
<mx:columns>
<mx:DataGridColumn dataField="lastName"
headerText="Last Name"
editable="false"/>
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation"
editorDataField="value">
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
Between the DataGridColumn control tags, create an itemEditor property tag block:
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation"
editorDataField="value">
<itemEditor>
</itemEditor>
</mx:DataGridColumn>
Between the itemRenderer tags, create a Component tag block:
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation"
editorDataField="value">
<itemEditor>
<fx:Component>
</fx:Component>
</itemEditor>
</mx:DataGridColumn>
Between the Component tags, create a MX NumericStepper control instance:
<fx:Component>
<mx:NumericStepper/>
</fx:Component>
To the NumericStepper control, assign 5 as the minimum and 9 as the maximum:
<mx:NumericStepper minimum="5" maximum="9"/>
Select an employee evaluation score and
click the up arrow button to increase the score as high as it can go. You
should see that the NumericStepper control will only step up to the
number 9 (see Figure 4).

Figure 4. Change the employee evaluation value to the maximum.
Click the down arrow until the minimum
number is displayed. You should see that the NumericStepper control
will only step down to the number 5 (see Figure 5).

Figure 5. Change the employee evaluation value to the minimum.
If you have multiple item renderers for a DataGrid component
instance, then the code can easily become unwieldy. In this section you will create
an item renderer in a separate class file and then apply it to the DataGridColumn instance.
From the Package Explorer view, right-click the src folder and select New > Folder (see Figure 6).

Figure 6. Create a new folder.
In the New Folder dialog box, enter components for the Folder name (see Figure 7).

Figure 7. Name the folder components.
In the Package Explorer view, right-click the components folder and select New > MXML component (see Figure 8).

Figure 8. Create a new MXML component.
Delete the Width and Height values.
Your New MXML Component dialog box should look as shown in Figure 9.

Figure 9. Name the component EvaluationDetail, base it on the Box container and remove the Width and Height values.
In the EvaluationDetail.mxml file, to the
opening Box tag, assign off as the horizontalScrollPolicy and verticalScrollPolicy and horizontal as the direction:
<mx:Box xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
horizontalScrollPolicy="off"
verticalScrollPolicy="off"
direction="horizontal">
Declarations tag block.Declarations tag block,
remove the generated code.Between the Declarations tag block,
create a DateFormatter component:
<fx:Declarations>
<mx:DateFormatter/>
</fx:Declarations>
To the DateFormatter control,
assign rendererDate as the id and MM-DD-YY as the formatString:
<fx:Declarations>
<mx:DateFormatter id="rendererDate"
formatString="MM-DD-YY"/>
</fx:Declarations>
Below the Declarations block,
create a Label control:
<fx:Declarations>
<mx:DateFormatter id="rendererDate"
formatString="MM-DD-YY"/>
</fx:Declarations>
<s:Label/>
To the Label control, assign 5 as the paddingLeft and paddingTop,
and the literal text Evaluation: followed by the data.evaluation value as the text property.
<s:Label paddingTop="5"
paddingLeft="5"
text="Evaluation:{data.evaluation}"/>
DataGrid control.DataGrid control tags,
delete the itemEditor tag block from the second DataGridColumn control
tag block. To the second DataGridColumn control,
assign components.EvaluationDetail as itemRenderer:
<mx:DataGridColumn dataField="evaluation"
headerText="Evaluation"
editorDataField="value"
itemRenderer="components.EvaluationDetail">
</mx:DataGridColumn>
Save the file and run the application.
You should see the Evaluation column resembles Figure 10.

Figure 10. Run the application to see the Evaluation column rendered by the component.
In this exercise, you learned how to use item editors and
renderers with the DataGrid control.
DataGridColumn control is used to create an inline item editor?itemEditor property.Trilemetry, Inc is a development and education organization that implements a human-centered design approach to the creation of software and content. Their Adobe portfolio includes the Adobe ColdFusion Getting Started Experience, the Adobe Flex Getting Started Experience, the Flex in a Week video series, the official Adobe instructor-led training course Flex 3: Extending and Styling Components and more. They also create and support many Web applications from interactive Flash sites and corporate web sites to mission-critical business applications.