2016-09-16 49 views
0

我想知道,我如何改變數據網格項目的背景顏色! 我使用外部CSS和使用Flex 4.6我使用:Flex中設計Apache DataGrid 4.15

s|ItemRenderer 
{ 
    contentBackgroundColor: #FF0000; 
} 

但我必須升級到Apache彎曲4.15,它不工作了......我找不到我想,以風格的組件。在文檔中我找不到T_T可用的樣式列表。

如果你有一個鏈接或答案thx!

+0

它是MX或Spark Datagrid的?你嘗試過GridItemRenderer而不是ItemRenderer嗎? – Nemi

回答

0

在Adobe的Flex的文檔它的表示:

項目渲染器與所述數據網格控制的列相關聯。項目渲染器然後控制列中每個單元格的外觀。但是,每個項呈示器都可以訪問DataGrid控件整行的數據項。使用項目渲染器的data屬性來訪問數據項目。

盡力去完成,通過使用ItemRenderer的滿足您的所有列,你可以做,在MXML方式或通過動作腳本代碼一樣應用樣式已知列混合MXL:

<mx:DataGrid x="29" y="303" width="694" height="190" dataProvider="{testData.book}" variableRowHeight="true"> 
<mx:columns> 
    <mx:DataGridColumn headerText="Title" dataField="title"> 
     <mx:itemRenderer> 
      <mx:Component> 
       <mx:HBox paddingLeft="2"> 
        <mx:Script> 
        <![CDATA[ 
         override public function set data(value:Object) : void { 
          super.data = value; 
          var today:Number = (new Date()).time; 
          var pubDate:Number = Date.parse(data.date); 
          if(pubDate > today) setStyle("backgroundColor",0xff99ff); 
          else setStyle("backgroundColor",0xffffff); 
         } 
        ]]> 
        </mx:Script> 
        <mx:Image source="{data.image}" width="50" height="50" scaleContent="true" /> 
        <mx:Text width="100%" text="{data.title}" /> 
       </mx:HBox> 
      </mx:Component> 
     </mx:itemRenderer> 
    </mx:DataGridColumn> 
</mx:columns> 

或在分離的動作腳本類中,通過排除所提到的腳本標記的內容到擴展列的類型並覆蓋設置數據方法的動作腳本類:

public class CheckBoxHeaderRenderer extends CheckBox 
{ 
    override public function set data(value:Object):void 
{ 
    _data = value as CheckBoxHeaderColumn; 
    selected = _data.selected; 
    //type your condition here using the property of your dataField 
    if(data.property=="value"){ 
    this.styleName="yourClassCSSName" 
    } 
} 

和你的類的CSS將是這樣的:

.yourClassCSSName{ 
contentBackgroundColor: #FF0000; 
} 

更多: Understanding Flex itemRenderers

Creating item renderers and item editors for the Spark DataGrid control