<?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: Setting background colors on a DataGrid column in Flex</title>
	<atom:link href="http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Sun, 12 Feb 2012 14:19:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: a.samy</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-8842</link>
		<dc:creator>a.samy</dc:creator>
		<pubDate>Mon, 17 Jan 2011 09:46:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-8842</guid>
		<description>Here is another solution for setting but for setting alternating column colors
http://www.flex4ex.com/?p=9</description>
		<content:encoded><![CDATA[<p>Here is another solution for setting but for setting alternating column colors<br />
<a href="http://www.flex4ex.com/?p=9" rel="nofollow">http://www.flex4ex.com/?p=9</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter deHaan</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-3867</link>
		<dc:creator>Peter deHaan</dc:creator>
		<pubDate>Wed, 04 Feb 2009 06:26:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-3867</guid>
		<description>Charles Shoults,

Can you please file a bug at http://bugs.adobe.com/flex/ and include a test case which shows the error.

Thanks,
Peter</description>
		<content:encoded><![CDATA[<p>Charles Shoults,</p>
<p>Can you please file a bug at <a href="http://bugs.adobe.com/flex/" rel="nofollow">http://bugs.adobe.com/flex/</a> and include a test case which shows the error.</p>
<p>Thanks,<br />
Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Shoults</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-3863</link>
		<dc:creator>Charles Shoults</dc:creator>
		<pubDate>Tue, 03 Feb 2009 23:34:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-3863</guid>
		<description>Well, I found that my problem is an apparent bug.  If showHeaders is false, the debug version of Flash Player 10 will throw an error.  A workaround is to keep headers visible, set their height to 1 and set their color to match the background of the columns, or as closely as possible.</description>
		<content:encoded><![CDATA[<p>Well, I found that my problem is an apparent bug.  If showHeaders is false, the debug version of Flash Player 10 will throw an error.  A workaround is to keep headers visible, set their height to 1 and set their color to match the background of the columns, or as closely as possible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Shoults</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-3869</link>
		<dc:creator>Charles Shoults</dc:creator>
		<pubDate>Tue, 03 Feb 2009 23:17:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-3869</guid>
		<description>I&#039;m looking at the examples and I suppose I&#039;m not sure how it knows what &quot;haloSilver&quot; is.  In my project, I have a DataGrid with five columns, populated by a PHP script that retrieves data from mysql.  The first column retrieves an image to display user rank while the next three columns display text.  The last column is currently unused.  One of the columns currently reads &#039;&#039;

I want to be able to set the background of the second, third and forth columns to #555555 but as soon as I try, I get script errors.

http://www.battletech-live.net/error1010.png</description>
		<content:encoded><![CDATA[<p>I&#8217;m looking at the examples and I suppose I&#8217;m not sure how it knows what &#8220;haloSilver&#8221; is.  In my project, I have a DataGrid with five columns, populated by a PHP script that retrieves data from mysql.  The first column retrieves an image to display user rank while the next three columns display text.  The last column is currently unused.  One of the columns currently reads &#8221;</p>
<p>I want to be able to set the background of the second, third and forth columns to #555555 but as soon as I try, I get script errors.</p>
<p><a href="http://www.battletech-live.net/error1010.png" rel="nofollow">http://www.battletech-live.net/error1010.png</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yogesh gaur</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-3868</link>
		<dc:creator>yogesh gaur</dc:creator>
		<pubDate>Wed, 28 Jan 2009 09:11:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-3868</guid>
		<description>Can you please provide an example on how to dynamically color any row of datagrib based on some event on datagrid row ????
                      thanks in advance :)</description>
		<content:encoded><![CDATA[<p>Can you please provide an example on how to dynamically color any row of datagrib based on some event on datagrid row ????<br />
                      thanks in advance :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhu</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-3859</link>
		<dc:creator>madhu</dc:creator>
		<pubDate>Fri, 02 Jan 2009 11:59:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-3859</guid>
		<description>my requirement is
mydatagrid contains two columns
column1  columnn2
true      12
false     15
true      16

if the value in column1 is true then the backgroundcolor of column2 must  be red or else if the value in column1 is false then the backgroundcolor of  column 2 must be
blue</description>
		<content:encoded><![CDATA[<p>my requirement is<br />
mydatagrid contains two columns<br />
column1  columnn2<br />
true      12<br />
false     15<br />
true      16</p>
<p>if the value in column1 is true then the backgroundcolor of column2 must  be red or else if the value in column1 is false then the backgroundcolor of  column 2 must be<br />
blue</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PKASH</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-3864</link>
		<dc:creator>PKASH</dc:creator>
		<pubDate>Mon, 29 Sep 2008 10:47:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-3864</guid>
		<description>how can u retrive the arraycollection field name in actionscript. like
arraycollection(col1:&#039;a&#039;,col2:&#039;b&#039;);
in this i want to col1.

If possible plase let me, how convert the colums as a rows?
arraycollection(a:&#039;col1&#039;,b:&#039;col2&#039;)</description>
		<content:encoded><![CDATA[<p>how can u retrive the arraycollection field name in actionscript. like<br />
arraycollection(col1:&#8217;a',col2:&#8217;b');<br />
in this i want to col1.</p>
<p>If possible plase let me, how convert the colums as a rows?<br />
arraycollection(a:&#8217;col1&#8242;,b:&#8217;col2&#8242;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-3860</link>
		<dc:creator>peterd</dc:creator>
		<pubDate>Sun, 28 Sep 2008 15:38:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-3860</guid>
		<description>Pierre,

To round to two decimals you can use &lt;code&gt;&lt;&lt;em&gt;Number&lt;/em&gt;&gt;.toFixed(2)&lt;/code&gt;, or you can use a CurrencyFormatter or NumberFormatter.

As for your other question, this should get you somewhat close, but there are still a few bugs in the code. Most notably:
(a) Rearranging columns in the top DataGrid control causes the column order in the top and bottom data grid to get out of sync.
(b) Changing data providers on the top DataGrid doesn&#039;t correctly update the values in the bottom DataGrid. You&#039;ll need to add additional logic/code.

&lt;pre class=&quot;code&quot;&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
        layout=&quot;vertical&quot;
        horizontalAlign=&quot;left&quot;
        verticalAlign=&quot;top&quot;
        initialize=&quot;init();&quot;&gt;

 &lt;mx:Script&gt;
  &lt;![CDATA[
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.controls.Label;
   import mx.controls.dataGridClasses.DataGridColumn;
   import mx.events.CollectionEvent;
   import mx.events.DataGridEvent;
   import mx.utils.ObjectUtil;

   private function resizeCols(event:Event=null) : void {
    if(dgS.rowCount &gt; dgS.dataProvider.length)
      dgtot.width = dgS.width;
     else
      dgtot.width = dgS.width-16;
   }

   private function resizeCol(event : DataGridEvent) : void {
    DataGridColumn(dgtot.columns[event.columnIndex]).width = DataGridColumn(dgS.columns[event.columnIndex]).width;
   }

   private function sum_labelFunc(item:Object, col:DataGridColumn):String {
    var sum:Number = Number(item.Price) * Number(item.Quantity);
    return currencyFormatter.format(sum);
   }

   private function currency_labelFunc(item:Object, col:DataGridColumn):String {
    return currencyFormatter.format(item[col.dataField]);
   }

   private function sum_sortCompareFunc(a:Object, b:Object):int {
    var sumA:Number = Number(sumCol.itemToLabel(a));
    var sumB:Number = Number(sumCol.itemToLabel(b));
    return ObjectUtil.numericCompare(sumA, sumB);
   }

   [Bindable]
   public var dpADG:ArrayCollection = new ArrayCollection([
    {Artist:&#039;Pavement&#039;,      Album:&#039;Slanted and Enchanted&#039;,  Price:11.99, Quantity:10},
    {Artist:&#039;Pavement&#039;,      Album:&#039;Brighten the Corners&#039;,   Price:11.99, Quantity:-12},
    {Artist:&#039;Saner&#039;,         Album:&#039;A Child Once&#039;,           Price:11.99, Quantity:30},
    {Artist:&#039;Saner&#039;,         Album:&#039;Helium Wings&#039;,           Price:12.99, Quantity:45},
    {Artist:&#039;The Doors&#039;,     Album:&#039;The Doors&#039;,              Price:10.99, Quantity:60},
    {Artist:&#039;The Doors&#039;,     Album:&#039;Morrison Hotel&#039;,         Price:12.99, Quantity:45},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;American Beauty&#039;,        Price:11.99, Quantity:23},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;In the Dark&#039;,            Price:11.99, Quantity:36},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;Shakedown Street&#039;,       Price:11.99, Quantity:73},
    {Artist:&#039;The Doors&#039;,     Album:&#039;Strange Days&#039;,           Price:12.99, Quantity:11},
    {Artist:&#039;The Doors&#039;,     Album:&#039;The Best of the Doors&#039;,  Price:10.99, Quantity:19},
    {Artist:&#039;The Doors2&#039;,    Album:&#039;The Best of the Doors2&#039;, Price:10.99, Quantity:21}
   ]);

   private var dpADG2:ArrayCollection = new ArrayCollection([
    {Artist:&#039;Pavement&#039;,      Album:&#039;Slanted and Enchanted&#039;, Price:11.99, Quantity:12},
    {Artist:&#039;Pavement&#039;,      Album:&#039;Brighten the Corners&#039;,  Price:11.99, Quantity:76},
    {Artist:&#039;Saner&#039;,         Album:&#039;A Child Once&#039;,          Price:11.99, Quantity:98},
    {Artist:&#039;Saner&#039;,         Album:&#039;Helium Wings&#039;,          Price:12.99, Quantity:54},
    {Artist:&#039;The Doors&#039;,     Album:&#039;The Doors&#039;,             Price:10.99, Quantity:79},
    {Artist:&#039;The Doors&#039;,     Album:&#039;Morrison Hotel&#039;,        Price:12.99, Quantity:28},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;American Beauty&#039;,       Price:11.99, Quantity:39},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;In the Dark&#039;,           Price:11.99, Quantity:30},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;Shakedown Street&#039;,      Price:11.99, Quantity:38}
   ]);

    private function init():void {
        dpADG.addEventListener(CollectionEvent.COLLECTION_CHANGE, dpADG_collectionChange);
        dpADG.refresh();
    }

    private var quantityTotal:Number;
    private var sumTotal:Number;

    private function dpADG_collectionChange(evt:CollectionEvent):void {
        quantityTotal = 0;
        sumTotal = 0;
        dpADG.source.forEach(quantitySum);
        var it:Object = dpADGTotal.getItemAt(0);
        it.Quantity = quantityTotal;
        it.Sum = sumTotal;
        dpADGTotal.setItemAt(it, 0);
    }

    private function quantitySum(item:*, index:int, array:Array):void {
        quantityTotal += item.Quantity;
        var sum:Number = Number(item.Price) * Number(item.Quantity);
        sumTotal += sum;
    }


   [Bindable]
   private var dpADGTotal:ArrayCollection = new ArrayCollection([
    {Artist:&#039;&#039;, Album:&#039;Total&#039;, Quantity:&#039;&#039;, Sum:&#039;&#039;}
   ]);

  ]]&gt;
 &lt;/mx:Script&gt;
 &lt;mx:Style&gt;
  .title {
   text-align: center;
   font-weight: bold;
  }
  .body {
   text-align: right;
   padding-right: 10;
  }
 &lt;/mx:Style&gt;

 &lt;mx:NumberFormatter id=&quot;numberFormatter&quot;/&gt;
 &lt;mx:CurrencyFormatter id=&quot;currencyFormatter&quot; precision=&quot;2&quot; /&gt;

 &lt;mx:Button label=&quot;{&#039;Switch to Dataprovider &#039;+ (dgS.dataProvider == dpADG ? &#039;without&#039; : &#039;with&#039;) +&#039;  scroll&#039;}&quot;
         click=&quot;dgS.dataProvider = (dgS.dataProvider == dpADG ? dpADG2 : dpADG);&quot;/&gt;

 &lt;mx:VBox width=&quot;100%&quot; height=&quot;100%&quot; verticalGap=&quot;0&quot;&gt;
  &lt;mx:DataGrid id=&quot;dgS&quot;
               dataProvider=&quot;{dpADG}&quot;
               height=&quot;40%&quot; width=&quot;100%&quot;
               resize=&quot;resizeCols();&quot;
               columnStretch=&quot;resizeCol(event);&quot;
               creationComplete=&quot;dgS.addEventListener(CollectionEvent.COLLECTION_CHANGE, resizeCols, false, 0, true);&quot;
               editable=&quot;true&quot;
               textAlign=&quot;right&quot;&gt;
   &lt;mx:columns&gt;
    &lt;mx:DataGridColumn id=&quot;dcArt&quot;
            dataField=&quot;Artist&quot;
            textAlign=&quot;left&quot;
            headerStyleName=&quot;title&quot; /&gt;
    &lt;mx:DataGridColumn dataField=&quot;Album&quot;
            textAlign=&quot;left&quot;
            headerStyleName=&quot;title&quot; /&gt;
    &lt;mx:DataGridColumn dataField=&quot;Quantity&quot;
            textAlign=&quot;right&quot;
            headerStyleName=&quot;title&quot;
            paddingRight=&quot;10&quot;
            editable=&quot;true&quot;
            itemEditor=&quot;mx.controls.NumericStepper&quot;
            editorDataField=&quot;value&quot; /&gt;
    &lt;mx:DataGridColumn dataField=&quot;Price&quot;
            textAlign=&quot;right&quot;
            headerStyleName=&quot;title&quot;
            paddingRight=&quot;10&quot;
            labelFunction=&quot;currency_labelFunc&quot; /&gt;
    &lt;mx:DataGridColumn id=&quot;sumCol&quot;
            textAlign=&quot;right&quot;
            headerStyleName=&quot;title&quot;
            paddingRight=&quot;10&quot;
            editable=&quot;false&quot;
            headerText=&quot;Sum&quot;
            labelFunction=&quot;sum_labelFunc&quot;
            sortCompareFunction=&quot;sum_sortCompareFunc&quot; /&gt;
   &lt;/mx:columns&gt;
  &lt;/mx:DataGrid&gt;
  &lt;mx:DataGrid id=&quot;dgtot&quot;
               width=&quot;40%&quot;
               dataProvider=&quot;{dpADGTotal}&quot;
               showHeaders=&quot;false&quot;
               rowCount=&quot;1&quot;
               height=&quot;{dgtot.rowHeight}&quot;
               creationComplete=&quot;{resizeCols()}&quot;
               fontWeight=&quot;bold&quot;&gt;
   &lt;mx:columns&gt;
    &lt;mx:DataGridColumn/&gt;
    &lt;mx:DataGridColumn dataField=&quot;Album&quot;
            textAlign=&quot;right&quot;
            fontStyle=&quot;italic&quot;
            paddingRight=&quot;10&quot; /&gt;
    &lt;mx:DataGridColumn dataField=&quot;Quantity&quot;
            textAlign=&quot;right&quot;
            paddingRight=&quot;10&quot; /&gt;
    &lt;mx:DataGridColumn dataField=&quot;Price&quot; /&gt;
    &lt;mx:DataGridColumn dataField=&quot;Sum&quot;
            textAlign=&quot;right&quot;
            paddingRight=&quot;10&quot;
            labelFunction=&quot;currency_labelFunc&quot; /&gt;
   &lt;/mx:columns&gt;
  &lt;/mx:DataGrid&gt;
 &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
&lt;/pre&gt;

Peter</description>
		<content:encoded><![CDATA[<p>Pierre,</p>
<p>To round to two decimals you can use <code>&lt;<em>Number</em>&gt;.toFixed(2)</code>, or you can use a CurrencyFormatter or NumberFormatter.</p>
<p>As for your other question, this should get you somewhat close, but there are still a few bugs in the code. Most notably:<br />
(a) Rearranging columns in the top DataGrid control causes the column order in the top and bottom data grid to get out of sync.<br />
(b) Changing data providers on the top DataGrid doesn&#8217;t correctly update the values in the bottom DataGrid. You&#8217;ll need to add additional logic/code.</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        horizontalAlign="left"
        verticalAlign="top"
        initialize="init();"&gt;

 &lt;mx:Script&gt;
  &lt;![CDATA[
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.controls.Label;
   import mx.controls.dataGridClasses.DataGridColumn;
   import mx.events.CollectionEvent;
   import mx.events.DataGridEvent;
   import mx.utils.ObjectUtil;

   private function resizeCols(event:Event=null) : void {
    if(dgS.rowCount &gt; dgS.dataProvider.length)
      dgtot.width = dgS.width;
     else
      dgtot.width = dgS.width-16;
   }

   private function resizeCol(event : DataGridEvent) : void {
    DataGridColumn(dgtot.columns[event.columnIndex]).width = DataGridColumn(dgS.columns[event.columnIndex]).width;
   }

   private function sum_labelFunc(item:Object, col:DataGridColumn):String {
    var sum:Number = Number(item.Price) * Number(item.Quantity);
    return currencyFormatter.format(sum);
   }

   private function currency_labelFunc(item:Object, col:DataGridColumn):String {
    return currencyFormatter.format(item[col.dataField]);
   }

   private function sum_sortCompareFunc(a:Object, b:Object):int {
    var sumA:Number = Number(sumCol.itemToLabel(a));
    var sumB:Number = Number(sumCol.itemToLabel(b));
    return ObjectUtil.numericCompare(sumA, sumB);
   }

   [Bindable]
   public var dpADG:ArrayCollection = new ArrayCollection([
    {Artist:'Pavement',      Album:'Slanted and Enchanted',  Price:11.99, Quantity:10},
    {Artist:'Pavement',      Album:'Brighten the Corners',   Price:11.99, Quantity:-12},
    {Artist:'Saner',         Album:'A Child Once',           Price:11.99, Quantity:30},
    {Artist:'Saner',         Album:'Helium Wings',           Price:12.99, Quantity:45},
    {Artist:'The Doors',     Album:'The Doors',              Price:10.99, Quantity:60},
    {Artist:'The Doors',     Album:'Morrison Hotel',         Price:12.99, Quantity:45},
    {Artist:'Grateful Dead', Album:'American Beauty',        Price:11.99, Quantity:23},
    {Artist:'Grateful Dead', Album:'In the Dark',            Price:11.99, Quantity:36},
    {Artist:'Grateful Dead', Album:'Shakedown Street',       Price:11.99, Quantity:73},
    {Artist:'The Doors',     Album:'Strange Days',           Price:12.99, Quantity:11},
    {Artist:'The Doors',     Album:'The Best of the Doors',  Price:10.99, Quantity:19},
    {Artist:'The Doors2',    Album:'The Best of the Doors2', Price:10.99, Quantity:21}
   ]);

   private var dpADG2:ArrayCollection = new ArrayCollection([
    {Artist:'Pavement',      Album:'Slanted and Enchanted', Price:11.99, Quantity:12},
    {Artist:'Pavement',      Album:'Brighten the Corners',  Price:11.99, Quantity:76},
    {Artist:'Saner',         Album:'A Child Once',          Price:11.99, Quantity:98},
    {Artist:'Saner',         Album:'Helium Wings',          Price:12.99, Quantity:54},
    {Artist:'The Doors',     Album:'The Doors',             Price:10.99, Quantity:79},
    {Artist:'The Doors',     Album:'Morrison Hotel',        Price:12.99, Quantity:28},
    {Artist:'Grateful Dead', Album:'American Beauty',       Price:11.99, Quantity:39},
    {Artist:'Grateful Dead', Album:'In the Dark',           Price:11.99, Quantity:30},
    {Artist:'Grateful Dead', Album:'Shakedown Street',      Price:11.99, Quantity:38}
   ]);

    private function init():void {
        dpADG.addEventListener(CollectionEvent.COLLECTION_CHANGE, dpADG_collectionChange);
        dpADG.refresh();
    }

    private var quantityTotal:Number;
    private var sumTotal:Number;

    private function dpADG_collectionChange(evt:CollectionEvent):void {
        quantityTotal = 0;
        sumTotal = 0;
        dpADG.source.forEach(quantitySum);
        var it:Object = dpADGTotal.getItemAt(0);
        it.Quantity = quantityTotal;
        it.Sum = sumTotal;
        dpADGTotal.setItemAt(it, 0);
    }

    private function quantitySum(item:*, index:int, array:Array):void {
        quantityTotal += item.Quantity;
        var sum:Number = Number(item.Price) * Number(item.Quantity);
        sumTotal += sum;
    }

   [Bindable]
   private var dpADGTotal:ArrayCollection = new ArrayCollection([
    {Artist:'', Album:'Total', Quantity:'', Sum:''}
   ]);

  ]]&gt;
 &lt;/mx:Script&gt;
 &lt;mx:Style&gt;
  .title {
   text-align: center;
   font-weight: bold;
  }
  .body {
   text-align: right;
   padding-right: 10;
  }
 &lt;/mx:Style&gt;

 &lt;mx:NumberFormatter id="numberFormatter"/&gt;
 &lt;mx:CurrencyFormatter id="currencyFormatter" precision="2" /&gt;

 &lt;mx:Button label="{'Switch to Dataprovider '+ (dgS.dataProvider == dpADG ? 'without' : 'with') +'  scroll'}"
         click="dgS.dataProvider = (dgS.dataProvider == dpADG ? dpADG2 : dpADG);"/&gt;

 &lt;mx:VBox width="100%" height="100%" verticalGap="0"&gt;
  &lt;mx:DataGrid id="dgS"
               dataProvider="{dpADG}"
               height="40%" width="100%"
               resize="resizeCols();"
               columnStretch="resizeCol(event);"
               creationComplete="dgS.addEventListener(CollectionEvent.COLLECTION_CHANGE, resizeCols, false, 0, true);"
               editable="true"
               textAlign="right"&gt;
   &lt;mx:columns&gt;
    &lt;mx:DataGridColumn id="dcArt"
            dataField="Artist"
            textAlign="left"
            headerStyleName="title" /&gt;
    &lt;mx:DataGridColumn dataField="Album"
            textAlign="left"
            headerStyleName="title" /&gt;
    &lt;mx:DataGridColumn dataField="Quantity"
            textAlign="right"
            headerStyleName="title"
            paddingRight="10"
            editable="true"
            itemEditor="mx.controls.NumericStepper"
            editorDataField="value" /&gt;
    &lt;mx:DataGridColumn dataField="Price"
            textAlign="right"
            headerStyleName="title"
            paddingRight="10"
            labelFunction="currency_labelFunc" /&gt;
    &lt;mx:DataGridColumn id="sumCol"
            textAlign="right"
            headerStyleName="title"
            paddingRight="10"
            editable="false"
            headerText="Sum"
            labelFunction="sum_labelFunc"
            sortCompareFunction="sum_sortCompareFunc" /&gt;
   &lt;/mx:columns&gt;
  &lt;/mx:DataGrid&gt;
  &lt;mx:DataGrid id="dgtot"
               width="40%"
               dataProvider="{dpADGTotal}"
               showHeaders="false"
               rowCount="1"
               height="{dgtot.rowHeight}"
               creationComplete="{resizeCols()}"
               fontWeight="bold"&gt;
   &lt;mx:columns&gt;
    &lt;mx:DataGridColumn/&gt;
    &lt;mx:DataGridColumn dataField="Album"
            textAlign="right"
            fontStyle="italic"
            paddingRight="10" /&gt;
    &lt;mx:DataGridColumn dataField="Quantity"
            textAlign="right"
            paddingRight="10" /&gt;
    &lt;mx:DataGridColumn dataField="Price" /&gt;
    &lt;mx:DataGridColumn dataField="Sum"
            textAlign="right"
            paddingRight="10"
            labelFunction="currency_labelFunc" /&gt;
   &lt;/mx:columns&gt;
  &lt;/mx:DataGrid&gt;
 &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
</pre>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-3866</link>
		<dc:creator>Pierre</dc:creator>
		<pubDate>Sat, 27 Sep 2008 10:46:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-3866</guid>
		<description>Hello Peter,

I have two questions in the script below:
- How round the result in each row of the sum column (2 decimales) , i tried toString but i have an error.
- Is it possible, and how, to pass the total quantity and the total sum in an other datagrid in order to display the result.

Thank for your help

Regards

&lt;pre class=&quot;code&quot;&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot; horizontalAlign=&quot;left&quot; verticalAlign=&quot;top&quot;&gt;
 &lt;mx:Script&gt;
  &lt;![CDATA[
   import mx.controls.Label;
   import mx.controls.dataGridClasses.DataGridColumn;
   import mx.utils.ObjectUtil;
   import mx.events.CollectionEvent;
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.events.DataGridEvent;

   private function resizeCols(event:Event=null) : void {
    if(dgS.rowCount &gt; dgS.dataProvider.length)
      dgtot.width = dgS.width;
     else
      dgtot.width = dgS.width-16;
   }

   private function resizeCol(event : DataGridEvent) : void {
    DataGridColumn(dgtot.columns[event.columnIndex]).width = DataGridColumn(dgS.columns[event.columnIndex]).width;
   }

   private function sum_labelFunc(item:Object, col:DataGridColumn):Number {
    var sum:Number = Number(item.Price) * Number(item.Quantity);
    return sum;
   }

   private function sum_sortCompareFunc(a:Object, b:Object):int {
    var sumA:Number = Number(sumCol.itemToLabel(a));
    var sumB:Number = Number(sumCol.itemToLabel(b));
    return ObjectUtil.numericCompare(sumA, sumB);
   }


   [Bindable]
   public var dpADG:ArrayCollection = new ArrayCollection([
    {Artist:&#039;Pavement&#039;,      Album:&#039;Slanted and Enchanted&#039;,  Price:11.99, Quantity:10},
    {Artist:&#039;Pavement&#039;,      Album:&#039;Brighten the Corners&#039;,   Price:11.99, Quantity:-12},
    {Artist:&#039;Saner&#039;,         Album:&#039;A Child Once&#039;,           Price:11.99, Quantity:30},
    {Artist:&#039;Saner&#039;,         Album:&#039;Helium Wings&#039;,           Price:12.99, Quantity:45},
    {Artist:&#039;The Doors&#039;,     Album:&#039;The Doors&#039;,              Price:10.99, Quantity:60},
    {Artist:&#039;The Doors&#039;,     Album:&#039;Morrison Hotel&#039;,         Price:12.99, Quantity:45},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;American Beauty&#039;,        Price:11.99, Quantity:23},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;In the Dark&#039;,            Price:11.99, Quantity:36},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;Shakedown Street&#039;,       Price:11.99, Quantity:73},
    {Artist:&#039;The Doors&#039;,     Album:&#039;Strange Days&#039;,           Price:12.99, Quantity:11},
    {Artist:&#039;The Doors&#039;,     Album:&#039;The Best of the Doors&#039;,  Price:10.99, Quantity:19},
    {Artist:&#039;The Doors2&#039;,    Album:&#039;The Best of the Doors2&#039;, Price:10.99, Quantity:21}
   ]);

   private var dpADG2:ArrayCollection = new ArrayCollection([
    {Artist:&#039;Pavement&#039;,      Album:&#039;Slanted and Enchanted&#039;, Price:11.99, Quantity:12},
    {Artist:&#039;Pavement&#039;,      Album:&#039;Brighten the Corners&#039;,  Price:11.99, Quantity:76},
    {Artist:&#039;Saner&#039;,         Album:&#039;A Child Once&#039;,          Price:11.99, Quantity:98},
    {Artist:&#039;Saner&#039;,         Album:&#039;Helium Wings&#039;,          Price:12.99, Quantity:54},
    {Artist:&#039;The Doors&#039;,     Album:&#039;The Doors&#039;,             Price:10.99, Quantity:79},
    {Artist:&#039;The Doors&#039;,     Album:&#039;Morrison Hotel&#039;,        Price:12.99, Quantity:28},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;American Beauty&#039;,       Price:11.99, Quantity:39},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;In the Dark&#039;,           Price:11.99, Quantity:30},
    {Artist:&#039;Grateful Dead&#039;, Album:&#039;Shakedown Street&#039;,      Price:11.99, Quantity:38}
   ]);

   [Bindable]
   private var dpADGTotal:ArrayCollection = new ArrayCollection([
    {Artist:&#039;&#039;, Album:&#039;Total&#039;, Quantity:&#039;XXX.XX&#039;}
   ]);

  ]]&gt;
 &lt;/mx:Script&gt;
 &lt;mx:Style&gt;
  .title {
   text-align:center;
   font-weight:bold;
  }
  .body {
   text-align:right;
   padding-right:10;
  }
 &lt;/mx:Style&gt;


 &lt;mx:NumberFormatter id=&quot;numberFormatter&quot;/&gt;


 &lt;mx:Button label=&quot;{&#039;Switch to Dataprovider &#039;+ (dgS.dataProvider == dpADG ? &#039;without&#039; : &#039;with&#039;) +&#039;  scroll&#039;}&quot; click=&quot;{dgS.dataProvider = (dgS.dataProvider == dpADG ? dpADG2 : dpADG)}&quot;/&gt;


 &lt;mx:VBox width=&quot;100%&quot; height=&quot;100%&quot; verticalGap=&quot;0&quot;&gt;
  &lt;mx:DataGrid id=&quot;dgS&quot;
               dataProvider=&quot;{dpADG}&quot;
               height=&quot;40%&quot; width=&quot;40%&quot;
               resize=&quot;{resizeCols()}&quot;
               columnStretch=&quot;{resizeCol(event)}&quot;
               creationComplete=&quot;{dgS.addEventListener(CollectionEvent.COLLECTION_CHANGE, resizeCols, false, 0, true)}&quot;
               editable=&quot;true&quot;
               textAlign=&quot;right&quot;&gt;
   &lt;mx:columns&gt;
    &lt;mx:DataGridColumn dataField=&quot;Artist&quot;   id=&quot;dcArt&quot; textAlign=&quot;left&quot;  headerStyleName=&quot;title&quot;/&gt;
    &lt;mx:DataGridColumn dataField=&quot;Album&quot;               textAlign=&quot;left&quot;  headerStyleName=&quot;title&quot;/&gt;
    &lt;mx:DataGridColumn dataField=&quot;Quantity&quot;            textAlign=&quot;right&quot; headerStyleName=&quot;title&quot; paddingRight=&quot;10&quot;
                       editable=&quot;true&quot; itemEditor=&quot;comps.MyNumericStepper&quot; editorDataField=&quot;value&quot;/&gt;
    &lt;mx:DataGridColumn dataField=&quot;Price&quot;               textAlign=&quot;right&quot; headerStyleName=&quot;title&quot; paddingRight=&quot;10&quot;/&gt;
    &lt;mx:DataGridColumn                      id=&quot;sumCol&quot; textAlign=&quot;right&quot; headerStyleName=&quot;title&quot; paddingRight=&quot;10&quot;
                       editable=&quot;false&quot;
                       headerText=&quot;Sum&quot;
                       labelFunction=&quot;sum_labelFunc&quot;
                       sortCompareFunction=&quot;sum_sortCompareFunc&quot; /&gt;
   &lt;/mx:columns&gt;
  &lt;/mx:DataGrid&gt;
  &lt;mx:DataGrid id=&quot;dgtot&quot;
               width=&quot;40%&quot;
               dataProvider=&quot;{dpADGTotal}&quot;
               showHeaders=&quot;false&quot;
               rowCount=&quot;1&quot;
               height=&quot;{dgtot.rowHeight}&quot;
               creationComplete=&quot;{resizeCols()}&quot;
               fontWeight=&quot;bold&quot;&gt;
   &lt;mx:columns&gt;
    &lt;mx:DataGridColumn/&gt;
    &lt;mx:DataGridColumn dataField=&quot;Album&quot;               textAlign=&quot;right&quot; fontStyle=&quot;italic&quot; paddingRight=&quot;10&quot;/&gt;
    &lt;mx:DataGridColumn dataField=&quot;Quantity&quot;            textAlign=&quot;right&quot;                    paddingRight=&quot;10&quot;/&gt;
    &lt;mx:DataGridColumn dataField=&quot;Price&quot;/&gt;
    &lt;mx:DataGridColumn                    id=&quot;sumLign&quot; textAlign=&quot;right&quot;                 paddingRight=&quot;10&quot;
                       labelFunction=&quot;sum_labelFunc&quot;/&gt;
   &lt;/mx:columns&gt;
  &lt;/mx:DataGrid&gt;
 &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hello Peter,</p>
<p>I have two questions in the script below:<br />
- How round the result in each row of the sum column (2 decimales) , i tried toString but i have an error.<br />
- Is it possible, and how, to pass the total quantity and the total sum in an other datagrid in order to display the result.</p>
<p>Thank for your help</p>
<p>Regards</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" horizontalAlign="left" verticalAlign="top"&gt;
 &lt;mx:Script&gt;
  &lt;![CDATA[
   import mx.controls.Label;
   import mx.controls.dataGridClasses.DataGridColumn;
   import mx.utils.ObjectUtil;
   import mx.events.CollectionEvent;
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.events.DataGridEvent;

   private function resizeCols(event:Event=null) : void {
    if(dgS.rowCount &gt; dgS.dataProvider.length)
      dgtot.width = dgS.width;
     else
      dgtot.width = dgS.width-16;
   }

   private function resizeCol(event : DataGridEvent) : void {
    DataGridColumn(dgtot.columns[event.columnIndex]).width = DataGridColumn(dgS.columns[event.columnIndex]).width;
   }

   private function sum_labelFunc(item:Object, col:DataGridColumn):Number {
    var sum:Number = Number(item.Price) * Number(item.Quantity);
    return sum;
   }

   private function sum_sortCompareFunc(a:Object, b:Object):int {
    var sumA:Number = Number(sumCol.itemToLabel(a));
    var sumB:Number = Number(sumCol.itemToLabel(b));
    return ObjectUtil.numericCompare(sumA, sumB);
   }

   [Bindable]
   public var dpADG:ArrayCollection = new ArrayCollection([
    {Artist:'Pavement',      Album:'Slanted and Enchanted',  Price:11.99, Quantity:10},
    {Artist:'Pavement',      Album:'Brighten the Corners',   Price:11.99, Quantity:-12},
    {Artist:'Saner',         Album:'A Child Once',           Price:11.99, Quantity:30},
    {Artist:'Saner',         Album:'Helium Wings',           Price:12.99, Quantity:45},
    {Artist:'The Doors',     Album:'The Doors',              Price:10.99, Quantity:60},
    {Artist:'The Doors',     Album:'Morrison Hotel',         Price:12.99, Quantity:45},
    {Artist:'Grateful Dead', Album:'American Beauty',        Price:11.99, Quantity:23},
    {Artist:'Grateful Dead', Album:'In the Dark',            Price:11.99, Quantity:36},
    {Artist:'Grateful Dead', Album:'Shakedown Street',       Price:11.99, Quantity:73},
    {Artist:'The Doors',     Album:'Strange Days',           Price:12.99, Quantity:11},
    {Artist:'The Doors',     Album:'The Best of the Doors',  Price:10.99, Quantity:19},
    {Artist:'The Doors2',    Album:'The Best of the Doors2', Price:10.99, Quantity:21}
   ]);

   private var dpADG2:ArrayCollection = new ArrayCollection([
    {Artist:'Pavement',      Album:'Slanted and Enchanted', Price:11.99, Quantity:12},
    {Artist:'Pavement',      Album:'Brighten the Corners',  Price:11.99, Quantity:76},
    {Artist:'Saner',         Album:'A Child Once',          Price:11.99, Quantity:98},
    {Artist:'Saner',         Album:'Helium Wings',          Price:12.99, Quantity:54},
    {Artist:'The Doors',     Album:'The Doors',             Price:10.99, Quantity:79},
    {Artist:'The Doors',     Album:'Morrison Hotel',        Price:12.99, Quantity:28},
    {Artist:'Grateful Dead', Album:'American Beauty',       Price:11.99, Quantity:39},
    {Artist:'Grateful Dead', Album:'In the Dark',           Price:11.99, Quantity:30},
    {Artist:'Grateful Dead', Album:'Shakedown Street',      Price:11.99, Quantity:38}
   ]);

   [Bindable]
   private var dpADGTotal:ArrayCollection = new ArrayCollection([
    {Artist:'', Album:'Total', Quantity:'XXX.XX'}
   ]);

  ]]&gt;
 &lt;/mx:Script&gt;
 &lt;mx:Style&gt;
  .title {
   text-align:center;
   font-weight:bold;
  }
  .body {
   text-align:right;
   padding-right:10;
  }
 &lt;/mx:Style&gt;

 &lt;mx:NumberFormatter id="numberFormatter"/&gt;

 &lt;mx:Button label="{'Switch to Dataprovider '+ (dgS.dataProvider == dpADG ? 'without' : 'with') +'  scroll'}" click="{dgS.dataProvider = (dgS.dataProvider == dpADG ? dpADG2 : dpADG)}"/&gt;

 &lt;mx:VBox width="100%" height="100%" verticalGap="0"&gt;
  &lt;mx:DataGrid id="dgS"
               dataProvider="{dpADG}"
               height="40%" width="40%"
               resize="{resizeCols()}"
               columnStretch="{resizeCol(event)}"
               creationComplete="{dgS.addEventListener(CollectionEvent.COLLECTION_CHANGE, resizeCols, false, 0, true)}"
               editable="true"
               textAlign="right"&gt;
   &lt;mx:columns&gt;
    &lt;mx:DataGridColumn dataField="Artist"   id="dcArt" textAlign="left"  headerStyleName="title"/&gt;
    &lt;mx:DataGridColumn dataField="Album"               textAlign="left"  headerStyleName="title"/&gt;
    &lt;mx:DataGridColumn dataField="Quantity"            textAlign="right" headerStyleName="title" paddingRight="10"
                       editable="true" itemEditor="comps.MyNumericStepper" editorDataField="value"/&gt;
    &lt;mx:DataGridColumn dataField="Price"               textAlign="right" headerStyleName="title" paddingRight="10"/&gt;
    &lt;mx:DataGridColumn                      id="sumCol" textAlign="right" headerStyleName="title" paddingRight="10"
                       editable="false"
                       headerText="Sum"
                       labelFunction="sum_labelFunc"
                       sortCompareFunction="sum_sortCompareFunc" /&gt;
   &lt;/mx:columns&gt;
  &lt;/mx:DataGrid&gt;
  &lt;mx:DataGrid id="dgtot"
               width="40%"
               dataProvider="{dpADGTotal}"
               showHeaders="false"
               rowCount="1"
               height="{dgtot.rowHeight}"
               creationComplete="{resizeCols()}"
               fontWeight="bold"&gt;
   &lt;mx:columns&gt;
    &lt;mx:DataGridColumn/&gt;
    &lt;mx:DataGridColumn dataField="Album"               textAlign="right" fontStyle="italic" paddingRight="10"/&gt;
    &lt;mx:DataGridColumn dataField="Quantity"            textAlign="right"                    paddingRight="10"/&gt;
    &lt;mx:DataGridColumn dataField="Price"/&gt;
    &lt;mx:DataGridColumn                    id="sumLign" textAlign="right"                 paddingRight="10"
                       labelFunction="sum_labelFunc"/&gt;
   &lt;/mx:columns&gt;
  &lt;/mx:DataGrid&gt;
 &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre</title>
		<link>http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/comment-page-1/#comment-3865</link>
		<dc:creator>Pierre</dc:creator>
		<pubDate>Fri, 26 Sep 2008 08:43:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/24/setting-background-colors-on-a-datagrid-column-in-flex/#comment-3865</guid>
		<description>Hello,

thank you for your prompt response.


Best regards.</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>thank you for your prompt response.</p>
<p>Best regards.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

