getColor() cant find

hi guys

I am trying to put colors in my datagrid cell
public class Tradegrid extends AdvancedDatagrid
{
private function getColor(itemRenderer:IListItemRenderer, defaultColor:Number):Number{
                  if(itemRenderer && itemRenderer.data.status == "Delinquent ")
                        return 0xff0000;
if(itemRenderer && itemRenderer.data.status == "yellow ")
                        return 0xffff00;
                  return defaultColor;
            }

}

I put a break point inside getColor() function but it doesnt stop there.
Do i need to 'override'  getColor() function  something like
override protected function getColor(itemRenderer:IListItemRenderer, defaultColor:Number):Number{
                  ...
}

I am using flex 3.5.
any help will be great..
thanks
royjaydAsked:
Who is Participating?
 
dgofmanConnect With a Mentor Commented:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
    <mx:Script>
        <![CDATA[
           
        ]]>
    </mx:Script>
    <mx:AdvancedDataGrid>
        <mx:dataProvider>
            <mx:Array>
                <mx:Object display="Option 1" value="value1" valid="true"/>
                <mx:Object display="Option 2" value="value2" valid="true"/>
                <mx:Object display="Option 3" value="value3" valid="false"/>
                <mx:Object display="Option 4" value="value4" valid="true"/>
            </mx:Array>
        </mx:dataProvider>
        <mx:itemRenderer>
            <mx:Component>
                <mx:AdvancedDataGridItemRenderer>
                    <mx:Script>
                        <![CDATA[
                            import mx.controls.dataGridClasses.DataGridColumn;
                            import mx.controls.dataGridClasses.DataGridListData;
                           
                            //Override Text color
                            override public function getTextStyles():TextFormat{
                                var tf:TextFormat = super.getTextStyles();
                                if(listData == null || data is DataGridColumn)
                                    return tf;
                                var valid:Object = data[DataGridListData(listData).dataField];
                                if(valid == true){
                                    tf.color = 0xff0000; //override text color
                                    this["background"] = true;
                                    this["backgroundColor"] = 0xffff00; //override background color
                                }else{
                                    this["background"] = false;
                                }
                                return tf;
                            }
                        ]]>
                    </mx:Script>
                </mx:AdvancedDataGridItemRenderer>
            </mx:Component>
        </mx:itemRenderer>
    </mx:AdvancedDataGrid>
</mx:Application>
0
 
dgofmanCommented:
I don't see problem in this function how can I help you?
0
 
royjaydAuthor Commented:
i put a break point on this line
if(itemRenderer && itemRenderer.data.status == "Delinquent ")

but it never stops here
Is getColor()  function of AdvancedDatagrid ?

thx
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
dgofmanCommented:
no, that is custom function
0
 
royjaydAuthor Commented:
actually this is my code

public class Tradegrid extends AdvancedDatagrid
{
public function Tradegrid ()
{
super();
}
private function getColor(itemRenderer:IListItemRenderer, defaultColor:Number):Number{
                  if(itemRenderer && itemRenderer.data.status == "Delinquent ")
                        return 0xff0000;
if(itemRenderer && itemRenderer.data.status == "yellow ")
                        return 0xffff00;
                  return defaultColor;
            }

}

0
 
dgofmanCommented:
Now add this function and you should able to debuging

            override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number,
                                                                                    height:Number, color:uint, dataIndex:int):void{
                  if(listItems)
                  {
                        var itemRenderer:IListItemRenderer = listItems[dataIndex][0];
                        color = getColor(itemRenderer, color);
                  }
                  super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
            }
0
 
royjaydAuthor Commented:
oh i am using flex 3.5 so i cant use 'Sprite'
0
 
dgofmanCommented:
Sprite is ActionScript core class you can use it in any SDK's
0
 
royjaydAuthor Commented:
ohk, let me try thanks
0
 
royjaydAuthor Commented:
can you tell me where i can find color code for
Red
Yellow
Green

I want to use it in my getColor()
thanks
0
 
dgofmanCommented:
R ed G renn B lue

red - 0xff0000
yellow - 0xffff00
gree - 0x00ff00
0
 
royjaydAuthor Commented:
thankyou

one question i have is
>>  var itemRenderer:IListItemRenderer = listItems[dataIndex][0];

this will be itemRenderer for every cell in the datagrid ? what does the [0] represent?

thx
0
 
dgofmanCommented:
what does the [0] represent?
0
 
royjaydAuthor Commented:
when i use this >>var itemRenderer:IListItemRenderer = listItems[dataIndex][0];

my itemRenderer is always null. i checked the listItems..My listItems is like this

listItems
[0]   mx...AdvancedDataGridGroupItemRenderer
[1]   mx...AdvancedDataGridGroupItemRenderer
[2]   mx...AdvancedDataGridGroupItemRenderer
[3]   mx...AdvancedDataGridGroupItemRenderer

so i am assuming it shoud be
var itemRenderer:IListItemRenderer = listItems[dataIndex];  

right?



0
 
royjaydAuthor Commented:
i think you are right, it is 2 dimensional array

but for some reason  var itemRenderer:IListItemRenderer = listItems[dataIndex][0];
is always null.

any idea why
0
 
dgofmanCommented:
how?
You should get at least first element
0
 
dgofmanCommented:
Please can you try to debug your self and I will review tomorrow. I have to go to bed
0
 
royjaydAuthor Commented:
yeah...i should atleast get the first item but i put debug point on

>>  var itemRenderer:IListItemRenderer = listItems[dataIndex][0];

the dataindex starts from 2, instead of 0, thats why itemRenderer is always null.

thanks for help...we can discuss later.
0
 
royjaydAuthor Commented:
we came up with this below code

customBackground() is our own function. we are overriding that
internally we are overriding drawRowBackground.
but the problem is it colors the entire row. I want to color only the cell ant not the entire row
 
override protected function customBackground():void{
var rowBGs:Sprite = Sprite(listContent.getChildByName("rowBGs"));
if (!rowBGs)
{
rowBGs = new FlexSprite();
rowBGs.name = "rowBGs";
rowBGs.mouseEnabled = false;
listContent.addChildAt(rowBGs, 0);
}
			
 var curRow:int = 0;			 
var i:int = 0;
var n:int = listItems.length;	

while (curRow < n)
{
				 
try
{
if (listItems[curRow][0])
{
	i++;
	var d:int = getItemDepth(listItems[i][0].data as Object, curRow);			drawRowBackground(rowBGs, i, rowInfo[curRow].y, rowInfo[curRow].height, 0x00ff00,curRow );
		} 
		else
		{
drawRowBackground(rowBGs, i, rowInfo[curRow].y, rowInfo[curRow].height, 0x00ff00,curRow );
							
	}
}
catch(e:Error)
{
				//
}
				 
curRow++;
}
			 
 
		}

Open in new window

0
 
dgofmanCommented:
That is easier you have to create an itemRenderer for a column
0
 
royjaydAuthor Commented:
can you please tell me how i can color only the cell. Business requirment is only the cell should be colored but not the enrire row..I am assuming this line is coloring the entire row
drawRowBackground(rowBGs, i, rowInfo[curRow].y, rowInfo[curRow].height, 0x00ff00,curRow );

any idea what i need to change?
0
 
royjaydAuthor Commented:
Thanks for all the help.
Can you please help with this question
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Flex/Q_27420400.html


thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.