Flex AdvancedDataGridItemRenderer 背景颜色/文本颜色不渲染

发布于 2024-07-13 15:52:26 字数 7030 浏览 12 评论 0 原文

我有以下扩展 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>

谢谢! 肖恩

I have the following class that extends AdvancedDataGridItemRenderer:

package
{
    import mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer;

    public class TestADGIR extends AdvancedDataGridItemRenderer
    {
            public function TestADGIR()
            {
                    super();
                    backgroundColor = 0; // black
                    textColor = 0xFFFFFF //16777215; // white
            }
    }
}

As you can see, the backgroundColor gets set to black and the textColor gets set to white in the constructor. I have an AdvancedDataGrid that uses the TestADGIR for one of the columns. But when the grid displays, that column is rendered with black text on a white background - the exact opposite of what is being set in the constructor. Could somebody could help me understand what I'm doing wrong? Here is the code for the 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>

Thanks!
Sean

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小巷里的女流氓 2024-07-20 15:52:26

我发现可以通过将 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.

就此别过 2024-07-20 15:52:26

这可能是因为 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

黑色毁心梦 2024-07-20 15:52:26

对于自定义行背景颜色我覆盖

protected function drawRowBackground(s:Sprite, rowIndex:int,
                                         y:Number, height:Number, color:uint, dataIndex:int):void

of ADG

For custom row background colors i override

protected function drawRowBackground(s:Sprite, rowIndex:int,
                                         y:Number, height:Number, color:uint, dataIndex:int):void

of ADG

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文