簡體   English   中英

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

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

我有一個關於在Flex 3 DataGrid中為行着色的問題。 我想將“基本”和“低於基本”行中的所有內容設為紅色:

<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>

我的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)}       



        }
     }
  }

}

我可以在“指標”列中看到“基本”和“低於基本”顯示為紅色。 但是,如何在“結果”列中獲取相應的值以顯示為紅色。 我不知道該如何引用這些單元格。

簡而言之,我想使整個“ Below”和“ Below Basic”行顯示為紅色。 有什么建議么?

如果您知道要比較的數據項始終為“指標”,則應顯式引用該數據項,因此無論您呈現的是哪一列,始終將條件邏輯應用於“指標”,從而使所有列均基於該數據項的值。

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