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:
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;
falseImg.visible = true;
<mx:Image id=”trueImg” src=”image” visible=”false” />
<mx:Image id=”falseImg” src=”image” visible=”false” />
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 ==
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.
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.
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.
- Rows and column header gets truncated while printing the datagrid
- Help we column chart display
- Datagrid column question
- Column widths in Spry dataset display
- How to hide blank columns in datagrid?
Related posts brought to you by Yet Another Related Posts Plugin.