【发布时间】:2011-07-30 19:43:36
【问题描述】:
似乎有多种方法可以设置数据网格的背景颜色。
见:How to dynamically change background colour of datagrid row?
见:Setting background color for datagrid row in Adobe Flex
我有一个以 HierarchicalData 作为数据源的高级数据网格。为此,我必须为父节点设置备用背景颜色,为子节点设置其他背景颜色。
<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>
我使用了alternatingItemColors 样式,但它没有按预期工作。
alternatingItemColors="[#449933, #994433]"
我需要为父节点和子节点设置交替颜色。
层次数据:
<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函数来实现。
见:http://flexpearls.blogspot.com/2008/02/row-background-color-in.html
有没有一种简单的方法来为 DataGrid 中使用的分层数据完成交替颜色设置。
【问题讨论】:
标签: apache-flex advanceddatagrid