Home > php教程 > PHP开发 > Flex custom DataGrid implements changing the background color based on a certain attribute value of the item

Flex custom DataGrid implements changing the background color based on a certain attribute value of the item

高洛峰
Release: 2016-12-27 16:55:51
Original
1364 people have browsed it

The code of the custom expanded DataGrid (as class) is as follows:

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);//设定颜色 
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; 
} 
 
 
} 
}
Copy after login

Implement the custom datagrid in mxml and use its rowColorFunction method

//通过比较每条记录中dataField为act和stand的大小决定该条记录的背景颜色 
private function setCustomColor(item:Object, color:uint):uint
{ 
if (Number(item["act"])<Number(item["stand"])) 
{ 
return 0x7bbfea; 
} 
 
return color; 
}
Copy after login

More Flex custom DataGrid implementation based on For articles related to changing the background color of a certain attribute value of an entry, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template