Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-03-2010, 11:11 AM   #1
Join Date: Apr 2007
Location: belgium
Posts: 68
Default Rendering Cell Items

I have following problem. I need to be able to render the content of a cell "delayed" based upon the content of cell "DelaySeverity". However the following renderer (BackgroundComp) only renders the background of the cell itself.

How can I modify this class such that I can render the cell based upon the content from another column ?

ActionScript Code:
<mx:Array>                 <mx:DataGridColumn  dataField="id" headerText="Airline" />                 <mx:DataGridColumn  dataField="cancelled" headerText="Cancelled Flights (%)"  />                 <mx:DataGridColumn  dataField="delayed" headerText="Delayed Flights (%)"  />                 <mx:DataGridColumn dataField="DelaySeverity" headerText="Delay" itemRenderer="BackgroundComp"  />             </mx:Array>

ActionScript Code:
package {     import mx.controls.Label;     import mx.controls.dataGridClasses.*;     import mx.controls.DataGrid;     import flash.display.Graphics;     import mx.styles.StyleManager;     [Style(name="backgroundColor", type="uint", format="Color", inherit="no")]         public class BackgroundComp extends Label {         override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void         {              super.updateDisplayList(unscaledWidth, unscaledHeight);                              var g:Graphics = graphics;              g.clear();              var grid1:DataGrid = DataGrid(DataGridListData(listData).owner);              if (grid1.isItemSelected(data) || grid1.isItemHighlighted(data))                  return;                               switch (data[DataGridListData(listData).dataField]) {                         case (1): {                                          g.beginFill(0xDE0033);                      g.drawRect(0, 0, unscaledWidth, unscaledHeight);                      g.endFill();                      break;                         }                                         case (2): {                                          g.beginFill(0x51DEED);                      g.drawRect(0, 0, unscaledWidth, unscaledHeight);                      g.endFill();                      break;                     }                                         case (3): {                                          g.beginFill(0x7CFFE3);                      g.drawRect(0, 0, unscaledWidth, unscaledHeight);                      g.endFill();                     break;                     }                                          } // switch                               } // override         } // class } // package
guide0 is offline   Reply With Quote
Old 02-05-2010, 06:07 PM   #2
drkstr's Avatar
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587

In my humble opinion, you are going about item renderers in the wrong way. They should be completely data driven, and not reference the outside world in any way (such as referencing the DataGrid). There are always exceptions to the rule, but your problem does not seem like one of them.

Here is a good overview on how item renderers work:


Essentially, each of the cells you want to render should have their own itemRenderer. Any visual changes they make should be the result of changes to it's 'data' property. Else wise, you will run into recycling issues.

drkstr is offline   Reply With Quote
Old 02-09-2010, 09:34 PM   #3
Join Date: Sep 2007
Posts: 58

Isn't data[DataGridListData(listData).dataField going to return a value like "delayed" or "cancelled"?

Something like this

ActionScript Code:
<mx:DataGridColumn  dataField="delayed" headerText="Delayed Flights (%)" itemRenderer="BackgroundComp"  /> <mx:DataGridColumn dataField="DelaySeverity" headerText="Delay" itemRenderer="BackgroundComp"  />
SeaOfHoles is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 06:18 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.