Flex 自定義DataGrid實(shí)現(xiàn)根據(jù)條目某一屬性值改變背景顏色
更新時間: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滾動條的皮膚代碼
使用css樣式修改TextArea滾動條的皮膚,具體示例代碼如下,感興趣的朋友可以參考下,希望對大家有所幫助2013-08-08Flex中如何動態(tài)生成DataGrid以及動態(tài)生成表頭
因某些需要,DataGrid及其表頭需要動態(tài)生成,網(wǎng)上的解決方案打多籠統(tǒng),下面有個不錯的解決方法,感興趣的朋友可以參考下2013-10-10flex 遍歷Object對象內(nèi)容的實(shí)現(xiàn)代碼
這篇文章主要介紹了flex 遍歷Object對象內(nèi)容的實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-07-07Flex調(diào)Javascript打開新窗口示例代碼
Flex通過調(diào)用Javascript打開全屏的新窗口新窗口示例代碼 ,具體實(shí)現(xiàn)代碼如下,感興趣的朋友可以參考下,希望對大家有所幫助2013-08-08