apache-flex - 在 AdvancedDataGrid 中设置一列的标题颜色不起作用

标签 apache-flex advanceddatagrid

需要帮助解决此问题。我需要更改标题颜色。 以下不起作用:

column.setStyle(StyleNames.HEADER_COLORS, "#FF7F00");

最佳答案

没有简单的方法可以在 AdvancedDataGrid 中仅设置一列标题的背景颜色。您需要为 header 使用自定义渲染器。

使用

<fx:Style>
    .yellowHeaderStyle {
        backgroundColor: yellow;
        backgroundAlpha: 1.0;
    }
</fx:Style>

<mx:AdvancedDataGrid dataProvider="{dataProvider}">
    <mx:columns>
        <mx:AdvancedDataGridColumn dataField="firstname" headerText="Firstname" />
        <mx:AdvancedDataGridColumn dataField="lastname" headerText="Lastname"
            headerRenderer="com.example.ColoredHeaderRenderer" headerStyleName="yellowHeaderStyle" />
    </mx:columns>
</mx:AdvancedDataGrid>

ColoredHeaderRenderer

package com.example
{
    import mx.controls.AdvancedDataGrid;
    import mx.controls.advancedDataGridClasses.AdvancedDataGridHeaderRenderer;
    import mx.controls.listClasses.BaseListData;

    [Style(name="backgroundColor", type="uint", format="Color")]
    [Style(name="backgroundAlpha", type="Number")]

    /**
     * The ColoredHeaderRenderer extends the default header renderer for a AdvancedDataGrid
     * control and adds styles for chaning the backgroundColor and backgroundAlpha.
     * 
     * <p>Both styles (backgroundColor and backgroundAlpha) must me set.</p>  
     */
    public class ColoredHeaderRenderer extends AdvancedDataGridHeaderRenderer
    {
        private var grid:AdvancedDataGrid;

        override public function set listData(value:BaseListData):void
        {
            super.listData = value;
            grid = AdvancedDataGrid(value.owner);
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);

            if (background)
            {
                background.graphics.clear();
                background.graphics.beginFill(getStyle("backgroundColor"), getStyle("backgroundAlpha"));

                // The function AdvancedDataGridBase.createHeaders() adds a padding to the top
                // and bottom of the HeaderRenderer. Let's undo this...
                background.graphics.drawRect(0, 0 - grid.getStyle("paddingTop"), unscaledWidth,
                    unscaledHeight + grid.getStyle("paddingTop") + grid.getStyle("paddingBottom") - 1);
                background.graphics.endFill();
            }
        }
    }
}

关于apache-flex - 在 AdvancedDataGrid 中设置一列的标题颜色不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15135721/

相关文章:

apache-flex - 如何将图标添加到 AdvancedDataGrid 列标题并保留文本的自动换行功能

apache-flex - 弹性 : Expand AdvancedDataGrid Tree Column programmatically

java - ActionScript 和 Java EE 中静态变量的区别

javascript - Flex (toFixed) 数字格式

apache-flex - AS3/Flex : Improving slow performance of drawing Application using BitmapData. 绘制()

apache-flex - Flex 内存限制 - 如何配置

iphone - 在 iPhone 上使用 AMF 而不是 JSON? (对于网络服务)

apache-flex - 如何确定数据网格中当前排序的标题列?