Flex AdvancedDataGridItemRenderer 背景颜色/文本颜色不渲染
我有以下扩展 AdvancedDataGridItemRenderer 的类:
package
{
import mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer;
public class TestADGIR extends AdvancedDataGridItemRenderer
{
public function TestADGIR()
{
super();
backgroundColor = 0; // black
textColor = 0xFFFFFF //16777215; // white
}
}
}
如您所见,在构造函数中,backgroundColor 设置为黑色,textColor 设置为白色。 我有一个 AdvancedDataGrid,它使用 TestADGIR 作为其中一列。 但是当网格显示时,该列会在白色背景上以黑色文本呈现 - 与构造函数中设置的内容完全相反。 有人可以帮助我理解我做错了什么吗? 这是 ADG 的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" preinitialize="preInitApp()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.HierarchicalCollectionView;
import mx.collections.HierarchicalCollectionViewCursor;
[Bindable]
private var dpFlat:ArrayCollection = new ArrayCollection([
{Region:"North", DisplayOrder: 2, Territory:"North1", Territory_Rep:"North1_Rep", ParticipantDisplayOrder: 1, Actual:38865, Estimate:40000},
{Region:"North", DisplayOrder: 2, Territory:"North2", Territory_Rep:"North2_Rep", ParticipantDisplayOrder: 2, Actual:29885, Estimate:30000},
{Region:"North", DisplayOrder: 2, Territory:"North3", Territory_Rep:"North3_Rep", ParticipantDisplayOrder: 3, Actual:29134, Estimate:30000},
{Region:"North", DisplayOrder: 2, Territory:"North4", Territory_Rep:"North4_Rep", ParticipantDisplayOrder: 4, Actual:52888, Estimate:45000},
{Region:"North", DisplayOrder: 2, Territory:"North5", Territory_Rep:"North5_Rep", ParticipantDisplayOrder: 5, Actual:38805, Estimate:40000},
{Region:"North", DisplayOrder: 2, Territory:"North6", Territory_Rep:"North6_Rep", ParticipantDisplayOrder: 6, Actual:55498, Estimate:40000},
{Region:"North", DisplayOrder: 2, Territory:"North6", Territory_Rep:"North6_Rep", ParticipantDisplayOrder: 7, Actual:44985, Estimate:45000},
{Region:"North", DisplayOrder: 2, Territory:"North8", Territory_Rep:"North8_Rep", ParticipantDisplayOrder: 8, Actual:44913, Estimate:45000},
{Region:"South", DisplayOrder: 1, Territory:"South1", Territory_Rep:"South1_Rep", ParticipantDisplayOrder: 1, Actual:38865, Estimate:40000},
{Region:"South", DisplayOrder: 1, Territory:"South2", Territory_Rep:"South2_Rep", ParticipantDisplayOrder: 2, ParticipantDisplayOrder: 2, Actual:29885, Estimate:30000},
{Region:"South", DisplayOrder: 1, Territory:"South3", Territory_Rep:"South3_Rep", ParticipantDisplayOrder: 3, Actual:29134, Estimate:30000},
{Region:"South", DisplayOrder: 1, Territory:"South4", Territory_Rep:"South4_Rep", ParticipantDisplayOrder: 4, Actual:52888, Estimate:45000},
{Region:"South", DisplayOrder: 1, Territory:"South5", Territory_Rep:"South5_Rep", ParticipantDisplayOrder: 5, Actual:38805, Estimate:40000},
{Region:"South", DisplayOrder: 1, Territory:"South6", Territory_Rep:"South6_Rep", ParticipantDisplayOrder: 6, Actual:55498, Estimate:40000},
{Region:"South", DisplayOrder: 1, Territory:"South7", Territory_Rep:"South7_Rep", ParticipantDisplayOrder: 7, Actual:44985, Estimate:45000},
{Region:"South", DisplayOrder: 1, Territory:"South8", Territory_Rep:"South8_Rep", ParticipantDisplayOrder: 8, Actual:44913, Estimate:45000}]);
[Bindable]
private var itemRendererFactory:ClassFactory = null;
private function preInitApp():void
{
itemRendererFactory = new ClassFactory(TestADGIR);
//itemRendererFactory.properties = {backgroundColor: 0, textColor: 16777215 };
}
private function sortByDisplayOrder(groupA:Object, groupB:Object, fields:Array = null):int
{
if (groupA.Region == groupB.Region) // if we are comparing two records from the same subgroup, then sort the participants
{
if (groupA.ParticipantDisplayOrder > groupB.ParticipantDisplayOrder)
{
return 1;
}
else if (groupA.ParticipantDisplayOrder == groupB.ParticipantDisplayOrder)
{
return 0;
}
else
{
return -1;
}
}
if (groupA.DisplayOrder > groupB.DisplayOrder) // sort the subgroups
{
return 1;
}
else if (groupA.DisplayOrder == groupB.DisplayOrder)
{
return 0;
}
else
{
return -1;
}
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%">
<mx:Panel title="AdvancedDataGrid Control Example"
height="100%" width="75%" layout="horizontal"
paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
<mx:AdvancedDataGrid id="myADG"
width="100%" height="100%"
initialize="gc.refresh();"
horizontalScrollPolicy="off"
displayItemsExpanded="true"
>
<mx:dataProvider>
<mx:GroupingCollection id="gc" source="{dpFlat}">
<mx:grouping>
<mx:Grouping compareFunction="sortByDisplayOrder">
<mx:GroupingField name="Region"/>
</mx:Grouping>
</mx:grouping>
</mx:GroupingCollection>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn id="regionColumn" dataField="Region" itemRenderer="{itemRendererFactory}"/>
<mx:AdvancedDataGridColumn id="territoryColumn" dataField="Territory"/>
<mx:AdvancedDataGridColumn id="territoryRepColumn" dataField="Territory_Rep"
headerText="Territory Rep"/>
<mx:AdvancedDataGridColumn id="actualColumn" dataField="Actual"/>
<mx:AdvancedDataGridColumn id="estimateColumn" dataField="Estimate"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Panel>
</mx:VBox>
</mx:Application>
谢谢! 肖恩
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现可以通过将 background 属性设置为 true 然后为 backgroundColor 属性分配一个值来操纵背景颜色。 文本颜色通过调用 setStyle("color", 0xFF0000) 进行操作。 感谢埃里克为我指明了正确的风格方向。
I discovered that the background color can be manipulated by setting the background property to true and then assigning a value to the backgroundColor property. The text color is manipulated by calling setStyle("color", 0xFF0000). Thanks to Eric for pointing me in the right direction on the styles.
这可能是因为 backgroundColor 和 textColor 不是 AdvancedDataGridItemRenderer 类的样式:
http://livedocs.adobe.com/flex/3/langref/mx/controls/advancedDataGridClasses/AdvancedDataGridItemRenderer.html#styleSummary
This could be because backgroundColor and textColor are not styles of the AdvancedDataGridItemRenderer Class:
http://livedocs.adobe.com/flex/3/langref/mx/controls/advancedDataGridClasses/AdvancedDataGridItemRenderer.html#styleSummary
对于自定义行背景颜色我覆盖
of ADG
For custom row background colors i override
of ADG