Notes on Java, Solaris, PHP, LDAP…

November 17, 2007

Parameterized renderers in Adobe Flex MXML

Filed under: Uncategorized — negev @ 8:05 pm
Tags:

4 April 2007

Parameterized renderers – re-using a renderer for several columns
Below is how to parameterize renderers. Then you can reuse a renderer for several columns. It’s useful when you need to highlight/render the whole row in same way, depending on its data. Note the curly brackets {}:
<mx:DataGrid…>
<mx:columns>
<mx:DataGridColumn dataField=”fullname” headerText=”Full Name” itemRenderer=”{new utils.MemberRendererFactory(‘fullname’)}” />

In MemberRenderer.mxml:

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Text xmlns:mx=”http://www.adobe.com/2006/mxml&#8221;
text=”{data[field]}” styleName=”{data.is_admin ? ‘adminStyle’ : ” }” >
<mx:Script>
<![CDATA[
[Bindable]
public var field: String= “default-field-here”;
]]>
</mx:Script>
</mx:Text>

In utils/MemberRendererFactory.as
we render a fields specially if the data row has ‘is_admin’ field set

package utils
{
import mx.core.IFactory;

public final class MemberRendererFactory implements IFactory
{
private var field: String;

public function MemberRendererFactory( givenField: String ) {
field= givenField;
}

public function newInstance(): *
{
var renderer:MemberRenderer = new MemberRenderer();
renderer.field= field;
return renderer;
}

}
}

A single-column renderer
<mx:DataGridColumn width=”27″ dataField=”my_field” headerText=”Some header” itemRenderer=”MemberStarRenderer” />

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: