<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Formatting a Flex DataGrid control using a custom item renderer</title>
	<atom:link href="http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Sun, 12 Feb 2012 19:26:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Anonymous</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-10349</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 31 Jan 2012 20:35:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-10349</guid>
		<description>Thanks, man.  Much appreciated.</description>
		<content:encoded><![CDATA[<p>Thanks, man.  Much appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rahul</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-10280</link>
		<dc:creator>Rahul</dc:creator>
		<pubDate>Wed, 28 Dec 2011 13:20:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-10280</guid>
		<description>Hi ,

I have a AdvancedDatagrid having a dataprovider. In one of the column there is a dropdownList (rendered) having a different data provider. On change of the dropdownlist i want to change the labels of one of the columns of Grid .
how can this be done ?
can you please reply ?

Thanks</description>
		<content:encoded><![CDATA[<p>Hi ,</p>
<p>I have a AdvancedDatagrid having a dataprovider. In one of the column there is a dropdownList (rendered) having a different data provider. On change of the dropdownlist i want to change the labels of one of the columns of Grid .<br />
how can this be done ?<br />
can you please reply ?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tahir Alvi</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-10176</link>
		<dc:creator>Tahir Alvi</dc:creator>
		<pubDate>Fri, 18 Nov 2011 12:07:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-10176</guid>
		<description>perfect solution</description>
		<content:encoded><![CDATA[<p>perfect solution</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lele</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-8804</link>
		<dc:creator>Lele</dc:creator>
		<pubDate>Wed, 05 Jan 2011 11:31:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-8804</guid>
		<description>Hi,
I have a problem with a data grid.
Rows in my data grid display data with line breaks so if a text content is composed by 3 lines my row height expand in order to display all content.
The problem is that the height of rows from what I see depends form the first row height but in my case sometimes first row has just one line and the third has 3 lines (but it&#039;s formatted as the first with one line height).
Hope you understand...
Thanks.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I have a problem with a data grid.<br />
Rows in my data grid display data with line breaks so if a text content is composed by 3 lines my row height expand in order to display all content.<br />
The problem is that the height of rows from what I see depends form the first row height but in my case sometimes first row has just one line and the third has 3 lines (but it&#8217;s formatted as the first with one line height).<br />
Hope you understand&#8230;<br />
Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sankara narayanan</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-8361</link>
		<dc:creator>Sankara narayanan</dc:creator>
		<pubDate>Mon, 27 Sep 2010 18:00:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-8361</guid>
		<description>Thanks a lot,
Helped great .
This is my Dictionary for flex.
:)
Regards,
Sankara narayanan Ekambaranathan.</description>
		<content:encoded><![CDATA[<p>Thanks a lot,<br />
Helped great .<br />
This is my Dictionary for flex.<br />
:)<br />
Regards,<br />
Sankara narayanan Ekambaranathan.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-7588</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 26 Apr 2010 10:58:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-7588</guid>
		<description>Thanks for your example and the nice comments there. 
I am facing a problem while trying to change the background. I am trying to change the background of specific cells that pass conditions. Like here I am testing if I have start Letter then I am testing if it delivered to the group leader or not by testing the dates of Start Letter and system date. Then if it is already sent to group leader, check if the group leader approved it or not. If not check the difference between the dates of the system date and the sent to group leader date. If the result is greater than 15 and less than 30, color that cell with red color. The other cells that are not used like manager will be in gray.  
If you could help me with this problem.
My code is the following:
        

	











package com.aramco.easd.ats.vo
{
	import flash.display.Graphics;
	
	import mx.controls.DataGrid;
	import mx.controls.Label;
	import mx.controls.dataGridClasses.*; 
    
    import mx.utils.StringUtil;
    
    [Style(name=&quot;backgroundColor&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
    
	public class BackgroundColor extends Label
	{
public var g:Graphics;
public function BackgroundColor()
{
	super();
}
		
		
		
	override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
	{
		super.updateDisplayList(unscaledWidth, unscaledHeight);
		g = graphics;
		g.clear();
		var grid1:DataGrid = DataGrid(DataGridListData(listData).owner);

		g = graphics;
		g.clear();
		unscaledWidth = this.unscaledWidth;
		unscaledHeight = this.unscaledHeight;
		     		     
		if (grid1.isItemSelected(data) &#124;&#124; grid1.isItemHighlighted(data))
			return;
		         
		checkStageLevel();
		     
		} // end of override function
public function checkStageLevel():void
{
	var systdate:Date  = new Date;
				
				
	// is the letter send or not to group leader
if ((data.tmldSentDt == null &#124;&#124; StringUtil.trim(data.tmldSentDt) == &quot;&quot;) &amp;&amp; (data.taskStaDt != null &#124;&#124; StringUtil.trim(data.taskStaDt) != &quot;&quot;))
	{
		checkDurationForStage(systdate, convertMyDate(data.taskStaDt));
	}// is the letter approved by group leader or waiting him/her to approve it
if ((data.tmldApvDt == null &#124;&#124; StringUtil.trim(data.tmldApvDt) == &quot;&quot;) &amp;&amp; (data.tmldSentDt != null &#124;&#124; StringUtil.trim(data.tmldSentDt) != &quot;&quot;))
	{
		checkDurationForStage(systdate, convertMyDate(data.tmldSentDt));
	}// is the letter approved by division head or waiting him/her to approve it

if(data.ltrdesc == &quot;Staking&quot; &#124;&#124; data.ltrdesc == &quot; Survey) 
{	
if ((data. mgraSentDt == data. mgraSentDt &#124;&#124; StringUtil.trim(data.dvhwSentDt) == &quot;&quot;) &amp;&amp; (data[DataGridListData(listData).dataField] == &quot;mgraSentDt&quot; &#124;&#124; StringUtil.trim(data[DataGridListData(listData).dataField]) == &quot;mgraSentDt&quot;))
{
	g.beginFill(0xA9A9A9);
	g.drawRect(0, 0, unscaledWidth, unscaledHeight);
	g.endFill();
}
if ((data. mgraApvDt == null &#124;&#124; StringUtil.trim(data. MgraApvDt) == &quot;&quot;) &amp;&amp; (data[DataGridListData(listData).dataField] == &quot;mgraApvDt&quot; &#124;&#124; StringUtil.trim(data[DataGridListData(listData).dataField]) == &quot;mgraApvDt&quot;))
{
	g.beginFill(0xA9A9A9);
	g.drawRect(0, 0, unscaledWidth, unscaledHeight);
	g.endFill();
}	  		
}

public function convertMyDate(strToCheck:String):Date {
	var uryear:String;
	var urmonth:String;
	var urday:String;
	var newDate:Date;
	    		
	uryear = strToCheck;
	if (uryear != null)
    	uryear = uryear.substr(uryear.length - 4, 4);
	
	urmonth = strToCheck;
	if (urmonth != null)
	    	urmonth = urmonth.substr(0, urmonth.indexOf(&quot;/&quot;));
	    		
	urday = strToCheck;	urday = urday.substr(0, urday.length - 5);
	if (urday != null)
	    	urday = urday.substr(3, urday.indexOf(&quot;/&quot;)+1);
	
newDate = new Date(Number(uryear),Number(urmonth)-1,Number(urday));
	    		
	return(newDate);
}

public function checkDurationForStage(systdate:Date, VariableDate:Date):void
{
	var ResultSysdate_VariableDate:Number = fromDates(VariableDate,systdate);
			
if ( 15 &lt; ResultSysdate_VariableDate &amp;&amp; ResultSysdate_VariableDate &lt;= 30 &amp;&amp; data[DataGridListData(listData).dataField] == data[DataGridListData(listData).dataField] )
	{
		g.beginFill(0xFF1234);
		g.drawRect(0, 0, unscaledWidth, unscaledHeight);
		g.endFill();
	}
else if ( 30 &lt; ResultSysdate_VariableDate &amp;&amp; ResultSysdate_VariableDate &lt;= 50 &amp;&amp; data[DataGridListData(listData).dataField] == data[DataGridListData(listData).dataField] )
	{
		g.beginFill(0xFF1111);
		g.drawRect(0, 0, unscaledWidth, unscaledHeight);
		g.endFill();
	}
}

public static function fromDates(start:Date, end:Date):Number 
{ 
	return Math.ceil((end.time - start.time)/MILLISECONDS_IN_DAY); 
} // end of fromDates function</description>
		<content:encoded><![CDATA[<p>Thanks for your example and the nice comments there.<br />
I am facing a problem while trying to change the background. I am trying to change the background of specific cells that pass conditions. Like here I am testing if I have start Letter then I am testing if it delivered to the group leader or not by testing the dates of Start Letter and system date. Then if it is already sent to group leader, check if the group leader approved it or not. If not check the difference between the dates of the system date and the sent to group leader date. If the result is greater than 15 and less than 30, color that cell with red color. The other cells that are not used like manager will be in gray.<br />
If you could help me with this problem.<br />
My code is the following:</p>
<p>package com.aramco.easd.ats.vo<br />
{<br />
	import flash.display.Graphics;</p>
<p>	import mx.controls.DataGrid;<br />
	import mx.controls.Label;<br />
	import mx.controls.dataGridClasses.*; </p>
<p>    import mx.utils.StringUtil;</p>
<p>    [Style(name="backgroundColor", type="uint", format="Color", inherit="no")]</p>
<p>	public class BackgroundColor extends Label<br />
	{<br />
public var g:Graphics;<br />
public function BackgroundColor()<br />
{<br />
	super();<br />
}</p>
<p>	override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void<br />
	{<br />
		super.updateDisplayList(unscaledWidth, unscaledHeight);<br />
		g = graphics;<br />
		g.clear();<br />
		var grid1:DataGrid = DataGrid(DataGridListData(listData).owner);</p>
<p>		g = graphics;<br />
		g.clear();<br />
		unscaledWidth = this.unscaledWidth;<br />
		unscaledHeight = this.unscaledHeight;</p>
<p>		if (grid1.isItemSelected(data) || grid1.isItemHighlighted(data))<br />
			return;</p>
<p>		checkStageLevel();</p>
<p>		} // end of override function<br />
public function checkStageLevel():void<br />
{<br />
	var systdate:Date  = new Date;</p>
<p>	// is the letter send or not to group leader<br />
if ((data.tmldSentDt == null || StringUtil.trim(data.tmldSentDt) == &#8220;&#8221;) &amp;&amp; (data.taskStaDt != null || StringUtil.trim(data.taskStaDt) != &#8220;&#8221;))<br />
	{<br />
		checkDurationForStage(systdate, convertMyDate(data.taskStaDt));<br />
	}// is the letter approved by group leader or waiting him/her to approve it<br />
if ((data.tmldApvDt == null || StringUtil.trim(data.tmldApvDt) == &#8220;&#8221;) &amp;&amp; (data.tmldSentDt != null || StringUtil.trim(data.tmldSentDt) != &#8220;&#8221;))<br />
	{<br />
		checkDurationForStage(systdate, convertMyDate(data.tmldSentDt));<br />
	}// is the letter approved by division head or waiting him/her to approve it</p>
<p>if(data.ltrdesc == &#8220;Staking&#8221; || data.ltrdesc == &#8221; Survey)<br />
{<br />
if ((data. mgraSentDt == data. mgraSentDt || StringUtil.trim(data.dvhwSentDt) == &#8220;&#8221;) &amp;&amp; (data[DataGridListData(listData).dataField] == &#8220;mgraSentDt&#8221; || StringUtil.trim(data[DataGridListData(listData).dataField]) == &#8220;mgraSentDt&#8221;))<br />
{<br />
	g.beginFill(0xA9A9A9);<br />
	g.drawRect(0, 0, unscaledWidth, unscaledHeight);<br />
	g.endFill();<br />
}<br />
if ((data. mgraApvDt == null || StringUtil.trim(data. MgraApvDt) == &#8220;&#8221;) &amp;&amp; (data[DataGridListData(listData).dataField] == &#8220;mgraApvDt&#8221; || StringUtil.trim(data[DataGridListData(listData).dataField]) == &#8220;mgraApvDt&#8221;))<br />
{<br />
	g.beginFill(0xA9A9A9);<br />
	g.drawRect(0, 0, unscaledWidth, unscaledHeight);<br />
	g.endFill();<br />
}<br />
}</p>
<p>public function convertMyDate(strToCheck:String):Date {<br />
	var uryear:String;<br />
	var urmonth:String;<br />
	var urday:String;<br />
	var newDate:Date;</p>
<p>	uryear = strToCheck;<br />
	if (uryear != null)<br />
    	uryear = uryear.substr(uryear.length &#8211; 4, 4);</p>
<p>	urmonth = strToCheck;<br />
	if (urmonth != null)<br />
	    	urmonth = urmonth.substr(0, urmonth.indexOf(&#8220;/&#8221;));</p>
<p>	urday = strToCheck;	urday = urday.substr(0, urday.length &#8211; 5);<br />
	if (urday != null)<br />
	    	urday = urday.substr(3, urday.indexOf(&#8220;/&#8221;)+1);</p>
<p>newDate = new Date(Number(uryear),Number(urmonth)-1,Number(urday));</p>
<p>	return(newDate);<br />
}</p>
<p>public function checkDurationForStage(systdate:Date, VariableDate:Date):void<br />
{<br />
	var ResultSysdate_VariableDate:Number = fromDates(VariableDate,systdate);</p>
<p>if ( 15 &lt; ResultSysdate_VariableDate &amp;&amp; ResultSysdate_VariableDate &lt;= 30 &amp;&amp; data[DataGridListData(listData).dataField] == data[DataGridListData(listData).dataField] )<br />
	{<br />
		g.beginFill(0xFF1234);<br />
		g.drawRect(0, 0, unscaledWidth, unscaledHeight);<br />
		g.endFill();<br />
	}<br />
else if ( 30 &lt; ResultSysdate_VariableDate &amp;&amp; ResultSysdate_VariableDate &lt;= 50 &amp;&amp; data[DataGridListData(listData).dataField] == data[DataGridListData(listData).dataField] )<br />
	{<br />
		g.beginFill(0xFF1111);<br />
		g.drawRect(0, 0, unscaledWidth, unscaledHeight);<br />
		g.endFill();<br />
	}<br />
}</p>
<p>public static function fromDates(start:Date, end:Date):Number<br />
{<br />
	return Math.ceil((end.time &#8211; start.time)/MILLISECONDS_IN_DAY);<br />
} // end of fromDates function</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rt</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-7231</link>
		<dc:creator>rt</dc:creator>
		<pubDate>Fri, 12 Mar 2010 02:17:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-7231</guid>
		<description>This is a good example but ItemRenderer works only with small amount of data. If you have a huge advanceddatagrid like say 50 columns and 1500 rows and you try to use an itemRenderer on it , your application will be really slow when you try to scroll horizontally or vertically. I had a similar advanced datagrid where I used itemrenderer and setStyle to show +ve numbers in blue and -ve numbers in red and it runs very slow.Let me know if you have a better solution to this problem or make it run faster. Try it when the data is getting updated every 10 seconds</description>
		<content:encoded><![CDATA[<p>This is a good example but ItemRenderer works only with small amount of data. If you have a huge advanceddatagrid like say 50 columns and 1500 rows and you try to use an itemRenderer on it , your application will be really slow when you try to scroll horizontally or vertically. I had a similar advanced datagrid where I used itemrenderer and setStyle to show +ve numbers in blue and -ve numbers in red and it runs very slow.Let me know if you have a better solution to this problem or make it run faster. Try it when the data is getting updated every 10 seconds</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-6706</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Wed, 30 Dec 2009 18:56:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-6706</guid>
		<description>Great example, yet again you saved the day for me.</description>
		<content:encoded><![CDATA[<p>Great example, yet again you saved the day for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sss4</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-5804</link>
		<dc:creator>sss4</dc:creator>
		<pubDate>Thu, 17 Sep 2009 05:42:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-5804</guid>
		<description>Never mind, I got it:
        &lt;pre lang=&quot;mxml&quot;&gt;private function cur_labelFunc(item:Object, column:DataGridColumn):String {
                return cF.format(item[column.dataField]);
            }&lt;/pre&gt;
See any problems with that?

Thanks again,

~S</description>
		<content:encoded><![CDATA[<p>Never mind, I got it:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;">private function cur_labelFunc(item:Object, column:DataGridColumn):String {
                return cF.format(item[column.dataField]);
            }</pre></div></div>

<p>See any problems with that?</p>
<p>Thanks again,</p>
<p>~S</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sss4</title>
		<link>http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/comment-page-1/#comment-5803</link>
		<dc:creator>sss4</dc:creator>
		<pubDate>Thu, 17 Sep 2009 04:29:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/#comment-5803</guid>
		<description>Thanks for the awesome example, I think the fact that you&#039;re still getting comments on a  two year old post speaks to the usefulness of it.

I have multiple columns that I need to run through a label function, can you think of a quick way to make the label function re-usable?

TIA, 

~S</description>
		<content:encoded><![CDATA[<p>Thanks for the awesome example, I think the fact that you&#8217;re still getting comments on a  two year old post speaks to the usefulness of it.</p>
<p>I have multiple columns that I need to run through a label function, can you think of a quick way to make the label function re-usable?</p>
<p>TIA, </p>
<p>~S</p>
]]></content:encoded>
	</item>
</channel>
</rss>

