复制代码 代码如下:
package org.lxh
{
import flash.display.Sprite;
import mx.controls.DataGrid;
public class SpecialDataGrid extends DataGrid
{
private var _rowColorFunction:Function; //用于在外部能通过指定一个方法 去实现改变列的背景色
public function SpecialDataGrid()
{
super();
}
public function set rowColorFunction(f:Function):void
{
this._rowColorFunction = f;
}
public function get rowColorFunction():Function
{
return this._rowColorFunction;
}
//复写该方法
override protected function drawRowBackground(s:Sprite,rowIndex:int,y:Number, height:Number, color:uint, dataIndex:int):void
{
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);
}
}
}
复制代码 代码如下:
<control:SpecialDataGrid alternatingItemColors="[0xe3eaf2,0xe8f1f8]" dataProvider="{strArray}" rowColorFunction="colorFunction" doubleClick="planDataGrid_doubleClickHandler(event)" doubleClickEnabled="true">
<control:columns>
<mx:DataGridColumn dataField="选择" sortable="false" resizable="false" showDataTips="true">
<mx:itemRenderer>
<fx:Component>
<mx:CheckBox change="outerDocument.checkChangeHandlerForPlan(event)"/>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="id" headerText="主键" visible="false"/>
</control:columns>
</control:SpecialDataGrid>
复制代码 代码如下:
(编辑:武林网)
新闻热点
疑难解答