I have a datagrid with a column that displays true or false
if an item “has children” or not. How would I go about placing an
image in the column depending on the value of the column. I want to
have two different images one for false and one for true.|||
You can use an itemrenderer, the adobe docs have extensive
documentation on how to use itemrenderer’s in a datagrid|||
i know itemrenderers are necessary however i can’t figure out
how to make the different image pop in, in regards to the value(t
or f) of the column

|||
make your item renderer a canvas, with 2 images.

when your canvas loads, you have the ‘data’ of that cell. So
lets say your column’s datafield is “hasimage”, you can do
something like this:

<mx:Canvas xmlns:mx=”
http://www.adobe.com/2006/mxml”
creationComplete=”created();”>

override public function set data(value:Object):void

{

if(value != null)

{

super.data = value;

}

}

public function created():void

{

if(data["hasimage"] == “true”)

trueImg.visible = true;

else

falseImg.visible = true;

}

<mx:Image id=”trueImg” src=”image” visible=”false” />

<mx:Image id=”falseImg” src=”image” visible=”false” />

</mx:Canvas>|||
This example is a bit contrived, but may be of some use. Not
sure why I can’t use data == ‘true’ instead of data.Good ==
‘true’|||
Thanks Greg, works exactly like i want it to. The only
difference is in my code the true/false is a Boolean value and not
a string. I wasn’t aware you could use the conditional operator in
the source. Big help.

Thanks,

Dev|||
I tried to get it to work with Boolean, but could not and did
not have time to dig deeper. If you figure that out please share.
Thanks!|||
your code works fine if you just make the string ‘true’ and
‘false’ just true and false (which turn them blue and makes them
the bool values) and do the same with the compare in the image
source. It outputs the correct image to the data field just as the
string version did.|||
Oh yeah. That didn’t work for me last time I tried.
Kool.

Related posts:

  1. Rows and column header gets truncated while printing the datagrid
  2. Help we column chart display
  3. Datagrid column question
  4. Column widths in Spry dataset display
  5. How to hide blank columns in datagrid?

Related posts brought to you by Yet Another Related Posts Plugin.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2012 free icons download Suffusion theme by Sayontan Sinha

Featuring Recent Posts WordPress Widget development by YD