Not yet rated

Problem

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.

Solution

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.

Detailed explanation

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();


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes