View comments | RSS feed
Packagemx.controls.listClasses
Interfacepublic interface IDropInListItemRenderer
ImplementorsButton, ComboBox, DataGridItemRenderer, DateField, Image, Label, ListBase, ListItemRenderer, MenuItemRenderer, NumericStepper, TextArea, TextInput, TileListItemRenderer, TreeItemRenderer

The interface for "drop-in" item renderers. Most IListItemRenderers are not "drop-ins". They are expecting to use a particular field of the data provider item. For example, they may assign the "lastName" property of the item to a Label's text property. This is easy to write using data-binding, but has the negative consequence that the renderer cannot be re-used in another column of a DataGrid or another List with different fields. IDropInListItemRenderer allows a renderer to be re-used. The list classes will pass more information to the renderer so that it can determine which field to use at run-time.

Components that you want to use as drop-in item renderers or drop-in item editors must implement the IDropInListItemRenderer interface. Many Flex component implement this interface, and therefore are usable as drop-in item renderers and drop-in item editors in any column or list.

Drop-in item renderers or drop-in item editors also must implement the IDataRenderer interface to define the data property.

When a component is used as a drop-in item renderer or drop-in item editor, Flex initializes the listData property of the component with the appropriate data from the list control. The component can then use the listData property to initialize the data property of the drop-in item renderer or drop-in item editor.

The listData property is of type BaseListData, where the BaseListData class has three subclasses: DataGridListData, ListData, and TreeListData. The actual data type of the value of the listData property depends on the control using the drop-in item renderer or item editor. For a DataGrid control, the value is of type DataGridListData, for a List control the value is of type ListData, and for a Tree control, the value is of type TreeListData.

The following example shows the setter method for the data property for the NumericStepper control that initializes NumericStepper's value property based on the value of the listData property:

    public function set data(value:Object):void
    {
      _data = value;
    
      this.value = _listData ? parseFloat(_listData.label) : Number(_data);
    
      dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
    }
  

In the example above, the NumericStepper control ignores the data property when setting NumericStepper's value property, and uses the listData property instead.

To implement the IDropInListItemRenderer interface, you define a setter and getter method to implement the listData property. Typically, the setter method writes the value of the listData property to an internal variable. The list class always assigns this property then sets the data provider item in the data property. Most implementations apply the listData either in the data setter, or in commitProperties() method because the data setter called the invalidateProperties() method or in response to the dataChange event because the data setter dispatched the event. The getter method returns the current value of the internal variable, as the following example shows:

    // Internal variable for the property value.
    private var _listData:BaseListData;
    
    // Make the listData property bindable.
    [Bindable("dataChange")]
    
    // Define the getter method.
    public function get listData():BaseListData
    {
      return _listData;
    }
    
    // Define the setter method,
    public function set listData(value:BaseListData):void
    {
      _listData = value;
    }
  

See also

mx.controls.listClasses.BaseListData
mx.core.IDataRenderer


Public Properties
 PropertyDefined by
  listData : BaseListData
Implements the listData property using setter and getter methods.
IDropInListItemRenderer
Property detail
listDataproperty
listData:BaseListData  [read-write]

Implements the listData property using setter and getter methods.

Implementation
    public function get listData():BaseListData
    public function set listData(value:BaseListData):void




Comments


No screen name said on Aug 20, 2006 at 8:05 PM :
"Most implementations apply the listData either in the data setter, or in commitProperties() method because the data setter called the invalidateProperties() method or in response to the dataChange event because the data setter dispatched the event. "

The sentence is hard for me to follow. As I read it:
Most implementations will apply the listData in one of two places. Most commonly you would just use the data setter. Alternately, you may apply the listData in the commitProperties() method. You would do this in the event that the data setter called the invalidateProperties() method or in the response to a dataChange event, as issued by the data setter.

Did I read that right? I can't tell.

You can apply the listData in the data setter or the commitProperties method. You would apply the listData in the data setter if .... You would apply the listData in the commitProperties if....
smgilson said on Aug 23, 2006 at 7:37 AM :
This sentence is a bid hard to swallow :)

Notice that the setter for listData does not dispatch an event. The idea is that the List classes always set listData, then set the data property. Setting the data property also dispatches the dataChange event. You never set listData on its own, so it doesn’t need to dispatch its own event.

The data setter could call invalidateProperties() if it did something that required the control to update itself. It would then be up to the component developer to write a commitProperties() method to determine that listData was modified, and handle it accordingly.

Stephen Gilson
Flex Doc Team

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/2/langref/mx/controls/listClasses/IDropInListItemRenderer.html