Flex 自定義DataGrid實(shí)現(xiàn)根據(jù)條目某一屬性值改變背景顏色
更新時(shí)間:2014年07月27日 14:37:49 投稿:whsnow
本節(jié)主要介紹了Flex DataGrid根據(jù)條目某一屬性值改變背景顏色,此DataGrid為自定義拓展的,需要的朋友可以參考下
自定義拓展的DataGrid(as類)代碼如下:
package czgh.components
{
import flash.display.Sprite;
import mx.controls.DataGrid;
import mx.core.UIComponent;
public class OptionalDataGrid extends DataGrid
{
private var _rowColorFunction:Function;
private var _customed:Boolean;
private var _customerColor:uint=0;
public function OptionalDataGrid()
{
super();
}
override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void
{
color=0XFFFFFF;
if(this._rowColorFunction != null)
{
if (dataIndex < this.dataProvider.length)
{
var item:Object=this.dataProvider.getItemAt(dataIndex);//設(shè)定顏色
color=this._rowColorFunction.call(this, item, color);
}
}
super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
}
override protected function drawHeaderBackground(headerBG:UIComponent):void
{
headerBG.setStyle("borderVisible","false");
}
public function set rowColorFunction(rowColorFunction:Function):void
{
this._rowColorFunction=rowColorFunction;
}
public function get rowColorFunction():Function
{
return this._rowColorFunction;
}
}
}
在mxml中實(shí)現(xiàn)自定義的datagrid并使用 其rowColorFunction方法
//通過比較每條記錄中dataField為act和stand的大小決定該條記錄的背景顏色
private function setCustomColor(item:Object, color:uint):uint
{
if (Number(item["act"])<Number(item["stand"]))
{
return 0x7bbfea;
}
return color;
}
相關(guān)文章
flex中使用css樣式修改TextArea滾動(dòng)條的皮膚代碼
使用css樣式修改TextArea滾動(dòng)條的皮膚,具體示例代碼如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-08-08
Flex中如何動(dòng)態(tài)生成DataGrid以及動(dòng)態(tài)生成表頭
因某些需要,DataGrid及其表頭需要?jiǎng)討B(tài)生成,網(wǎng)上的解決方案打多籠統(tǒng),下面有個(gè)不錯(cuò)的解決方法,感興趣的朋友可以參考下2013-10-10
flex4獲取當(dāng)前窗口的長(zhǎng)度與寬度的方法
讓新窗口看上去像新的一頁,于是就投機(jī)想讓PopUp的窗口界面大小自適應(yīng)屏幕,下面是flex4 獲取當(dāng)前窗口的長(zhǎng)度與寬度示例,需要的朋友可以參考下2014-07-07
flex 遍歷Object對(duì)象內(nèi)容的實(shí)現(xiàn)代碼
這篇文章主要介紹了flex 遍歷Object對(duì)象內(nèi)容的實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-07-07
Flex調(diào)Javascript打開新窗口示例代碼
Flex通過調(diào)用Javascript打開全屏的新窗口新窗口示例代碼 ,具體實(shí)現(xiàn)代碼如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-08-08

