tags:

views:

239

answers:

2

On a DataGrid, setting alternatingItemColors will apply the color scheme to all of the columns of that grid. I'm looking for a way to define different alternating colors for each column. Is there a baked in way to do this?

A: 

I hope this would be helpful for you ;)

public class BlocksTable extends DataGrid     
{
 public static const VALID_COLOR:uint   = 0xDBAB21;
 public static const INVALID_COLOR:uint = 0xC7403E;

 public function BlocksTable()
 {
  super();         
 }

 override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void
 {
  var contentHolder:ListBaseContentHolder = ListBaseContentHolder(s.parent);
  var background:Shape;
  if (rowIndex < s.numChildren)
  {
   background = Shape(s.getChildAt(rowIndex));             
  }
  else
  {
   background = new FlexShape();
            background.name = "background";
            s.addChild(background);
        }

        background.y = y;

        // Height is usually as tall is the items in the row, but not if
        // it would extend below the bottom of listContent
        var height:Number = Math.min(height,
                                     contentHolder.height -
                                     y);

        var g:Graphics = background.graphics;
        g.clear();

        var fillColor:uint;
        if(dataIndex < this.dataProvider.length)
        {
            if(this.dataProvider.getItemAt(dataIndex).IS_VALID)
            {
                fillColor = VALID_COLOR;
            }
            else
            {
                fillColor = INVALID_COLOR;
            }
        }
        else
        {
            fillColor = color;
        }
        g.beginFill(fillColor, getStyle("backgroundAlpha"));
        g.drawRect(0, 0, contentHolder.width, height);
        g.endFill();
    }
}
EugeneOnFlex