似乎有多种方法可以为数据网格设置背景色。
另请: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中使用的分层数据的备用颜色设置。
最佳答案
简而言之,没有。据我所知,没有一种“简单”的方法可以基于深度(父/子)为 AdvancedDataGrid
设置不同的交替行颜色。
最接近所需内容的是 depthColors
属性,但这会将该深度的所有行设置为一种颜色,而不是交替显示行。
关于apache-flex - 为AdvancedDataGrid设置替代颜色-一种用于父节点,另一种用于子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5566786/