Define custom renderer for the cell's in question.  The renderer gets
the data for the entire row and can then compute the background color.
I've had trouble actually setting backgroundColor in renderer but
binding the backgroundColor to a private var and setting that variable
to the color works.

 

<?xml version="1.0" encoding="utf-8"?>

<mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009"; 

                        xmlns:s="library://ns.adobe.com/flex/spark" 

                        xmlns:mx="library://ns.adobe.com/flex/mx" 

                         horizontalScrollPolicy="off"

                        >

<fx:Script>

      <![CDATA[

            public static var PAYOR_COLORS:Object ={"0":0xFE8EB8,
"1":0x87F19B, "3":0x9dbffc, "8":0xffff00};

            

            [Bindable]

            private var bg:int =0xFE8EB8;

            

            [Bindable]

            private var content:String;

            

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

                  super.data = value

                  var empty:Boolean = (value==null ||
value.resident__id=="0");

                  if (yofred!=null)

                        yofred.visible = !empty;

                  bg = PAYOR_COLORS[value.payor];

                  content = value.name ;

                  //if (color==0)   color=0xffffff;

                  

                  

            }

      ]]>

</fx:Script>

      <s:Label id="yofred" text="{content}" backgroundColor="{bg}"
width="100%" height="30" backgroundAlpha="1.0"/>

      

</mx:VBox>

 

 

From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On
Behalf Of isa_loyer
Sent: Saturday, October 29, 2011 4:08 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Flex 4.5 - Cell background color in datagrid

 

  

Hi,

I load some data with httpservice.
In those data, I have a backgound color for each cell.
Can you explain how to do to change background color accordind data in
dataprovider?
I thinks I must use itemrender but I don't found how to use dataprovider
data to do that.

Thaks for helping.



Reply via email to