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.