AdvancedDataGridColumn组单元格颜色

时间:2013-01-18 05:13:52

标签: actionscript-3 flex flex3

如何指定Flex中AdvancedDataGridColumnGroup中包含的特定单元格内的文本颜色?代码在动作脚本中,文本颜色根据单元格包含的值而变化。即如果是负值,则必须以红色显示,否则显示为黑色。

请提及是否有任何解决方法!

谢谢!

1 个答案:

答案 0 :(得分:0)

我已经完成了您描述的功能的示例。希望,这会有所帮助              

        <mx:AdvancedDataGrid id="grid"
                             itemRenderer="MyAdvancedDataGridItemRenderer"
                             dataProvider="{dataProvider}"
                             width="200" height="100%">

            <mx:groupedColumns>
                <mx:AdvancedDataGridColumn dataField="name"/>
                <mx:AdvancedDataGridColumn dataField="score"/>
            </mx:groupedColumns>
        </mx:AdvancedDataGrid>

        <mx:Script>  
            <![CDATA[  
                import mx.collections.ArrayCollection;

                [Bindable]  
                private var dataProvider:ArrayCollection = new ArrayCollection([  
                    {name:"Name1", score:-12},   
                    {name:"Name2", score:10},   
                    {name:"Name3", score:-100},   
                ]);
            ]]>  
        </mx:Script> 
    </mx:Application>

类MyAdvancedDataGridItemRenderer.as:

package
{
    import mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer;
    import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;

    public class MyAdvancedDataGridItemRenderer extends AdvancedDataGridItemRenderer
    {

        public function MyAdvancedDataGridItemRenderer()
        {
            super();
        }

        override public function validateProperties():void
        {
            super.validateProperties();
            if (listData)
            {
                var item:Object = AdvancedDataGridListData(listData).item;
                if (AdvancedDataGridListData(listData).dataField == "score") {
                    setStyle("color", item.score < 0 ? 0xff0000 : 0x000000);
                }
            }
        }
    }

}