为 AdvancedDataGrid 设置替代颜色 - 一种用于父节点,另一种用于子节点 [英] Set alternate color for AdvancedDataGrid - one for parent node and other for child nodes

查看:25
本文介绍了为 AdvancedDataGrid 设置替代颜色 - 一种用于父节点,另一种用于子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有多种方法可以为数据网格设置背景颜色.

It seems there are various ways to set the background color for a datagrid.

参见:如何动态更改数据网格行的背景颜色?

请参阅:在 Adob​​e Flex 中设置数据网格行的背景颜色

我有一个以 HierarchicalData 作为数据源的高级数据网格.为此,我必须为父节点设置备用背景颜色,为子节点设置另一种背景颜色.

I have a advanced datagrid with HierarchicalData as the datasource. For this, i have to set alternate background color one for the parent node and other for the child nodes.

<mx:AdvancedDataGrid id="electionGrid" alternatingItemColors="[#449933, #994433]" width="100%" height="70%" folderOpenIcon="{null}" folderClosedIcon="{null}" defaultLeafIcon="{null}" editable="true">
        <mx:dataProvider>
            <mx:HierarchicalData source="{electionSummary}" childrenField="electionOptions"/>
        </mx:dataProvider>
        <mx:columns>
            <mx:AdvancedDataGridColumn dataField="product" headerText="Product" editable="false"/>              
            <mx:AdvancedDataGridColumn dataField="accountID" headerText="Account ID" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="accountDescription" headerText="Account Description" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="electionOption" headerText="Election Options" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="electionStatus" headerText="Election Status" editable="true"/>
            <mx:AdvancedDataGridColumn dataField="entitledQuantity" headerText="Entitled Quantity"/> 
            <mx:AdvancedDataGridColumn dataField="electedQuantity" headerText="Elected Quantity"/>
            <mx:AdvancedDataGridColumn dataField="percentelectionDetails" headerText="Election %Details"/>
            <mx:AdvancedDataGridColumn dataField="comments" headerText="Comments"/>
        </mx:columns>        
    </mx:AdvancedDataGrid>

我使用了alternateItemColors 样式,但它没有按预期工作.

I have used alternatingItemColors style but it is not working as expected.

alternatingItemColors="[#449933, #994433]"

我需要为父节点和子节点设置交替颜色.

I need to set alternate color for parent node and child node.

分层数据:

<mx:ArrayCollection id="electionSummary">
    <model:Elections product="Global PB" accountID="10473834" accountDescription="Fund 1.2 Account" entitledQuantity="250000"
                        electedQuantity="0" percentelectionDetails="0">    
        <model:electionOptions>
            <mx:ArrayCollection id="optionData1">
                <model:Options electionStatus="Not Submitted"/>
            </mx:ArrayCollection>
        </model:electionOptions>
    </model:Elections>

    <model:Elections product="Global PB" accountID="10473834" accountDescription="Fund 1.2 Account" entitledQuantity="250000"
                        electedQuantity="0" percentelectionDetails="0">    
        <model:electionOptions>
            <mx:ArrayCollection id="optionData2">
                <model:Options electionStatus="Not Submitted"/>
            </mx:ArrayCollection>
        </model:electionOptions>
    </model:Elections>

    <model:Elections product="Global PB" accountID="10473834" accountDescription="Fund 1.2 Account" entitledQuantity="250000"
                        electedQuantity="0" percentelectionDetails="0">    
        <model:electionOptions>
            <mx:ArrayCollection id="optionData3">
                <model:Options electionStatus="Not Submitted"/>
            </mx:ArrayCollection>
        </model:electionOptions>
    </model:Elections>
</mx:ArrayCollection>

也可以通过覆盖 datagrid 中的 drawRowBackground 函数来实现.

It can also accomplished by overriding drawRowBackground function in datagrid.

参见:http://flexpearls.blogspot.com/2008/02/row-background-color-in.html

是否有一种简单的方法可以为 DataGrid 中使用的分层数据完成交替颜色设置.

Is there a simple way to accomplish alternate color setting for a hiearchical data used in DataGrid.

推荐答案

简而言之,没有.据我所知,没有简单"的方法可以为 AdvancedDataGrid 基于深度(父/子).

In short, no. To my knowledge there's no "simple" way to set different alternating row colors for an AdvancedDataGrid based on depth (parent/child).

最接近你想要的是 depthColors 属性,但会将该深度处的所有行设置为颜色,而不是交替行.

The closest thing to what you want is the depthColors property but that will set all rows at that depth to a color, not alternating rows.

这篇关于为 AdvancedDataGrid 设置替代颜色 - 一种用于父节点,另一种用于子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆