You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Deepak MS <me...@gmail.com> on 2014/07/02 08:26:06 UTC
Spark GridItemRenderer
Hello,
I was generating columns for a datagrid dynamically, but wanted to align
number columns on right and hence I used following code to assign renderer
to the gridcolumn:
var gc:GrdiColumn = new GridColum('Growth');
var ir:ClassFactory = new ClassFactory(SpreadItemRenderer);
ir.properties = {textAlign:'right'};
gc.itemRenderer = ir;
SpreadItemRenderer.as :
public class SpreadItemRenderer extends GridItemRenderer
{
public var textAlign:String;
public function SpreadFormatRenderer()
{
super();
}
override protected function createChildren() : void
{
super.createChildren();
if(labelDisplay)
{
labelDisplay.setStyle("textAlign", textAlign);
}
}
}
But, when I do that, column do not display any data in the datagrid. When I
debugged, I see that labelDisplay is always null. Isn't labelDisplay used
to display data under GridItemRenderer?
What am I missing here?
I am using Flex 4.12.0 | AIR 4.0 | FP 12.0 for a mobile app (iPad).
Re: Spark GridItemRenderer
Posted by João Fernandes <jo...@gmail.com>.
try to set a breakpoint in the labelDisplay setter function so you can
check when the object is created.
On 3 July 2014 12:09, Deepak MS <me...@gmail.com> wrote:
> My only requirement was to align the columns towards right and I thought
> setting textAlign property for labelDisplay would work normally. But it
> doesn't seem to, as labelDisplay is always null, I dont know why.
>
> So now, I am adding another label child to my itemrenderer and it does the
> job. But why is labelDisplay null if we extend GridItemRenderer? I could
> have avoided adding another child and performance would have been even
> better I feel.
>
> This is what I am doing right now:
> public class SpreadNormalRenderer extends GridItemRenderer
> {
> public var dataField:String;
> public var textAlign:String = 'left';
>
> private var normalLabel:StyleableTextField;
> public function SpreadNormalRenderer()
> {
> super();
> }
>
> [Bindable("dataChange")]
>
> override protected function createChildren() : void
> {
> super.createChildren();
> normalLabel = new StyleableTextField();
> normalLabel.setStyle("color", AppColors.BLACK);
> normalLabel.setStyle("textAlign", textAlign);
> addElement(normalLabel);
> }
>
> override protected function commitProperties():void
> {
> super.commitProperties();
> if(data)
> {
> normalLabel.text = data[dataField];
> }
>
> }
>
> override protected function updateDisplayList(
> unscaledWidth:Number, unscaledHeight:Number ) : void
> {
> super.updateDisplayList(unscaledWidth, unscaledHeight);
> normalLabel.width = unscaledWidth;
> normalLabel.height = unscaledHeight;
> }
>
> override public function set data(value:Object):void
> {
> // TODO Auto Generated method stub
> super.data = value;
> invalidateProperties();
> dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
> }
> }
>
> And thanks for the references... : )
>
>
> On Wed, Jul 2, 2014 at 5:22 PM, MichaPooh <ra...@yahoo.fr> wrote:
>
> > Hellothe labelDisplay in GridItemRenderer is only optimal, because you
> > could
> > want to create other stuff like a checkbox, a chart component or
> something
> > else...You have to create an ItemRenderer based on GridItemRenderer where
> > you declare/set the labelDisplay.An easy example as a MXML renderer would
> > be:
> >
> >
> >
> > --
> > View this message in context:
> >
> http://apache-flex-users.2333346.n4.nabble.com/Spark-GridItemRenderer-tp7130p7134.html
> > Sent from the Apache Flex Users mailing list archive at Nabble.com.
> >
>
--
João Fernandes
Re: Spark GridItemRenderer
Posted by Deepak MS <me...@gmail.com>.
My only requirement was to align the columns towards right and I thought
setting textAlign property for labelDisplay would work normally. But it
doesn't seem to, as labelDisplay is always null, I dont know why.
So now, I am adding another label child to my itemrenderer and it does the
job. But why is labelDisplay null if we extend GridItemRenderer? I could
have avoided adding another child and performance would have been even
better I feel.
This is what I am doing right now:
public class SpreadNormalRenderer extends GridItemRenderer
{
public var dataField:String;
public var textAlign:String = 'left';
private var normalLabel:StyleableTextField;
public function SpreadNormalRenderer()
{
super();
}
[Bindable("dataChange")]
override protected function createChildren() : void
{
super.createChildren();
normalLabel = new StyleableTextField();
normalLabel.setStyle("color", AppColors.BLACK);
normalLabel.setStyle("textAlign", textAlign);
addElement(normalLabel);
}
override protected function commitProperties():void
{
super.commitProperties();
if(data)
{
normalLabel.text = data[dataField];
}
}
override protected function updateDisplayList(
unscaledWidth:Number, unscaledHeight:Number ) : void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
normalLabel.width = unscaledWidth;
normalLabel.height = unscaledHeight;
}
override public function set data(value:Object):void
{
// TODO Auto Generated method stub
super.data = value;
invalidateProperties();
dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
}
}
And thanks for the references... : )
On Wed, Jul 2, 2014 at 5:22 PM, MichaPooh <ra...@yahoo.fr> wrote:
> Hellothe labelDisplay in GridItemRenderer is only optimal, because you
> could
> want to create other stuff like a checkbox, a chart component or something
> else...You have to create an ItemRenderer based on GridItemRenderer where
> you declare/set the labelDisplay.An easy example as a MXML renderer would
> be:
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Spark-GridItemRenderer-tp7130p7134.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>
Re: Spark GridItemRenderer
Posted by MichaPooh <ra...@yahoo.fr>.
Hellothe labelDisplay in GridItemRenderer is only optimal, because you could
want to create other stuff like a checkbox, a chart component or something
else...You have to create an ItemRenderer based on GridItemRenderer where
you declare/set the labelDisplay.An easy example as a MXML renderer would
be:
--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Spark-GridItemRenderer-tp7130p7134.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.
RE: Spark GridItemRenderer
Posted by Kessler CTR Mark J <ma...@usmc.mil>.
Possibly listen for the dataChange event[1] or override the data setter[2] for the renderer. Handle assignment of the data yourself, checking for nulls/ bad values.
[1] http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/gridClasses/GridItemRenderer.html#event:dataChange
[2] http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/gridClasses/GridItemRenderer.html#data
-Mark
-----Original Message-----
From: Deepak MS [mailto:megharajdeepak@gmail.com]
Sent: Wednesday, July 02, 2014 2:26 AM
To: users@flex.apache.org
Subject: Spark GridItemRenderer
Hello,
I was generating columns for a datagrid dynamically, but wanted to align
number columns on right and hence I used following code to assign renderer
to the gridcolumn:
var gc:GrdiColumn = new GridColum('Growth');
var ir:ClassFactory = new ClassFactory(SpreadItemRenderer);
ir.properties = {textAlign:'right'};
gc.itemRenderer = ir;
SpreadItemRenderer.as :
public class SpreadItemRenderer extends GridItemRenderer
{
public var textAlign:String;
public function SpreadFormatRenderer()
{
super();
}
override protected function createChildren() : void
{
super.createChildren();
if(labelDisplay)
{
labelDisplay.setStyle("textAlign", textAlign);
}
}
}
But, when I do that, column do not display any data in the datagrid. When I
debugged, I see that labelDisplay is always null. Isn't labelDisplay used
to display data under GridItemRenderer?
What am I missing here?
I am using Flex 4.12.0 | AIR 4.0 | FP 12.0 for a mobile app (iPad).