如何设置不同的列以在DataGrid列上具有交替的项目颜色?

时间:2009-12-03 19:34:31

标签: flex

在DataGrid上,设置alternatingItemColors会将颜色方案应用于该网格的所有列。我正在寻找一种为每列定义不同交替颜色的方法。是否有烘焙方式来做到这一点?

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我希望这会对你有所帮助;)

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