发布于2026-07-22 阅读(0)
扫一扫,手机访问
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;
}
}
}
那么,在MXML里用起来也很直观。这里用了一个简单的回调函数,通过比较每条记录里`act`和`stand`字段的值,来决定这一行的背景色。
// 如果act的值小于stand,就把这一行的底色设成浅蓝色,否则就保留默认颜色
private function setCustomColor(item:Object, color:uint):uint {
if (Number(item["act"])
这样一来,你就有了一个可以根据数据自动变色的DataGrid,非常实用。
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
8