Set alternate color for AdvancedDataGrid - one for parent node and other for child nodes

橙三吉。 提交于 2019-12-14 03:49:29

问题


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

See: How to dynamically change background colour of datagrid row?

See: Setting background color for datagrid row in Adobe Flex

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>

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.

Hiearchical Data:

<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>

It can also accomplished by overriding drawRowBackground function in datagrid.

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

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


回答1:


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).

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.



来源:https://stackoverflow.com/questions/5566786/set-alternate-color-for-advanceddatagrid-one-for-parent-node-and-other-for-chi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!