Feb 8, 2009

Item Renderes: Part 1: Introduction

Lets start with the definition of the term item renderers and item editors

According to me:

Item renderes and item editors are set of instruction or a piece of code which customize the appearance and/or behavior of items in list based components.

Sometime people get confused between item renderers and item editors.
So, before going further, Let me draw a comparison between them

Item rendere versus item editors
  • Both item renderes and item editors receive data in a data property from a list contol

  • The item renderer uses the data for purly for display and can't pass back data to list controls while item editor can pass data back from the controls that then becomes the new value of the edited items

  • Visually item renderes and item editors behaves differently and item renders is used all the times while an item editor is used only when item is being edited

Item Renderers and item editors could be of following three types:
1. Drop in
2. Inline
3. Component

Drop in item renederes and item editors
When you specify a control as a value again itemRenderer or itemEditor property of the control it would be called as a drop in item renderer or item editor

Example:
As item renderer
<mx:DataGridColumn dataField="completed"
headerText="Completed"
itemRenderer="mx.controls.CheckBox"
/>

As item editor
<mx:DataGridColumn dataField="quantity"
headerText="Quantity"
itemEditor="mx.controls.NumericStepper"
editorDataField="value"/>


Inline item renederes and item editors
when we write item renderes and item editor within a DataGridColumn tag block using
and tag respectively they are known as inline item renderes or editors.
Example

Inline Item Renderes
<mx:datagridcolumn datafield="someData"&gt
<mx:itemrenderer>
<mx:component>
<mx:Text selectable="false"
text="{dataObj.name}"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
Inline Item Editor
<mx:datagridcolumn datafield="someData">
<mx:itemeditCoor>
<mx:component>
<mx:NumericStepper minimum="0"
maximum="10"/>
</mx:Component>
</mx:itemEditor>
</mx:DataGridColumn>

Component Item renderers and item editors

When a inline item renderer get complex, its better to make it in a separate file as an independent component. When we do so, it is know as component item renderer or item editor.
It 0pen almost a new paradigm of opportunities which lets developer ease of resume and provides greater flexibility and functionality.

Example:

Make a separate file say myFirstItemRender.mxml
<mx:DataGridColumn dataField="someData" itemRenderer="myFirstRenderer.mxml"/>

Don't forget to mention the folder if of you component file if their is any. Say you saved all your renderes or editor files under renderers folder then you should include it like this:
<mx:DataGridColumn dataField="someData" itemRenderer="renderers.myFirstRenderer.mxml"/>

We will discuss about these various types of item renderers and item editors with a lot of other things in detail with coming series of articles on this topic.

Hope you enjoyed reading this article.
I would be interested in your feedback about this article.

Thanks,
Shaleen Jain

4 comments:

  1. Hey shaleen.. it was nice article specially the difference b/w item renderer and item editor.. Is it possible to write a repeater code purely in AS.

    ReplyDelete
  2. Hey Sandeep,

    thanks for the comments...
    Yes you can do it....Are you facing any issue in action script implementation of Repeater component?

    ReplyDelete
  3. NO actually i didnt tried to do a sample pgm , I was just asking coz how we will specify on which container we have to repeat ?

    var repeat:Repeater = new repeater();
    repeat.dataProvider = dp;

    but repeat on what? how we will specify this..suppose i am having an Grid within a VBox and i want the grid to be repeater..
    How we will tell this to the framework in AS.

    thanks
    Sandeep

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete