简体   繁体   English

如何在Flex 3中使用ItemRenderer有条件地为DataGrid行文本着色

[英]How Can I Conditionally Color DataGrid Row Text Using an ItemRenderer in Flex 3

I've got a question about coloring rows in a Flex 3 DataGrid. 我有一个关于在Flex 3 DataGrid中为行着色的问题。 I'd like to make everything in the "Basic" and "Below Basic" row red: 我想将“基本”和“低于基本”行中的所有内容设为红色:

<mx:DataGrid id="myGrid" 
   width="450"  
   dataProvider="{initDG}" 
   showHeaders="false">

   <mx:columns>
    <mx:DataGridColumn dataField="Indicator" itemRenderer="com.dcscore.ColorCells2"/>
    <mx:DataGridColumn  id="schoolColumn" dataField="Result"  fontWeight="bold"  itemRenderer="com.dcscore.ColorCells2"/>
    </mx:columns> 
</mx:DataGrid>

My ItemRenderer is: 我的ItemRenderer是:

package com.mySite {

    import mx.controls.Label;
    import mx.controls.dataGridClasses.*;

    public class ColorCells2 extends Label {
         override public function set data(value:Object):void
     {
        if(value != null)
        {
           super.data = value;

                if(value[DataGridListData(listData).dataField] == "Basic:"){
                  setStyle("color", 0xFF0000)}

                if(value[DataGridListData(listData).dataField] == "Below Basic:"){
                  setStyle("color", 0xFF0000)}       



        }
     }
  }

}

I can get "Basic" and "Below Basic" to appear red in the Indicator column. 我可以在“指标”列中看到“基本”和“低于基本”显示为红色。 But, how do I get the corresponding values in the Result column to appear red. 但是,如何在“结果”列中获取相应的值以显示为红色。 I don't know how to reference those cells. 我不知道该如何引用这些单元格。

In short, I want to make the entire "Below" and "Below Basic" rows appear red. 简而言之,我想使整个“ Below”和“ Below Basic”行显示为红色。 Any suggestions? 有什么建议么?

If you know that the data item you are comparing against is always "Indicator" then reference that data item explicitly, so regardless of which column you are rendering your conditional logic is always applied to "Indicator", resulting in all columns being colored based on the value of that data item. 如果您知道要比较的数据项始终为“指标”,则应显式引用该数据项,因此无论您呈现的是哪一列,始终将条件逻辑应用于“指标”,从而使所有列均基于该数据项的值。

override public function set data(value:Object):void
{
  if(value != null)
  {
     super.data = value;

     if(value["Indicator"] == "Basic:")
       setStyle("color", 0xFF0000);

     if(value["Indicator"] == "Below Basic:")
       setStyle("color", 0xFF0000);
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM