I want to use an itemRenderer for multiple columns that changes background colour of a cell depending on the data. The default renderer for a DataGrid cell does not have BackgroundColor. In the update DisplayList function, to draw your own background, you have to create a custom itemRenderer to do the task.
For example, two columns of X and Y values are created in a DataGrid: if any of the values exceeds 100, the cell background will be red. I will use the same itemRenderer for both columns since the two columns behave the same.
Here is Action Script itemRenderer package {
import mx.controls.Label;
import mx.controls.DataGrid;
import mx.controls.dataGridClasses.*;
import flash.display.Graphics;
public class CustomBackgroundComp extends Label {
override protected function updateDisplayList (unscaledWidth:Number, unscaledHeight:Number):void
{
super.updatedDisplayList (unscaledWidth, unscaledHeight);
var g:Graphics=graphics;
g. clear ();
var grid1:DataGrid=DataGridListData(ListData).owner); if grid1.isItemSelected(data)||grid1.isItemHighlighted (data))
return; if (data[DataGridListData(listData).dataField]>100) { g.beginFill(OxFF0033); g.drawRect (0,0, unscaledWidth, unscaledHeight); g.endFill();
+