看看我的来源:
[代码]
<mx:Script source="ListStatus.as" />
<!-- Template -->
<mx:DataGrid id="grid" width="100%" height="100%" doubleClick="editRecord();">
<mx:columns >
<mx:DataGridColumn width="30" resizable="false" draggable="false">
<mx:itemRenderer>
<mx:Component>
<mx:LinkButton icon="@Embed('assets/img/delete.png')" click="outerDocument.deleteRecord(event);" />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Nome" dataField="name" />
<mx:DataGridColumn headerText="Nome de exibição" dataField="displayName" />
<mx:DataGridColumn headerText="Cor" dataField="color" />
</mx:columns>
</mx:DataGrid>
[/代码]
[代码] 进口燃料。阿贾克斯; 进口燃料。模块; import fuel.window.Window;
import mx.controls.Alert; import mx.events.ModuleEvent; import mx.modules.ModuleLoader;
public var win:Window;
/ **
*构造函数
*
*从涡轮齿轮控制器获取数据
* /
public function init():void
{
showLoading();
Ajax.requestJSON('/ access / status / getList',{},function(obj:Object):void {
hideLoading();
grid.dataProvider = obj.results;
});
}
/ ** *致电表格编辑记录 * / public function editRecord():void {
try {
grid.selectedItem.id;
} catch(e:Error) {
Alert.show("Você deve selecionar um registro válido", "Atenção");
return;
}
var module:ModuleLoader = new ModuleLoader();
module.url = "access/CreateStatus.swf";
module.applicationDomain = ApplicationDomain.currentDomain;
module.addEventListener( ModuleEvent.READY, onModuleReady );
var title_bar:String = "Edição de Status (" + grid.selectedItem.id + ")";
if( this.window ){
win = this.window.openChild(title_bar, module, 410, 250);
} else {
win = (parentApplication as Admin).winManager.openWindow(title_bar, module, 410, 250);
}
}
/ ** *呼叫控制器删除记录 * / private function actionDeleteRecord(resp:Object):void { if(resp.detail == Alert.YES){ grid.enabled = false;
Ajax.requestJSON( "/access/status/delete", { 'id' : grid.selectedItem.id }, function( obj:Object ):void {
if (obj.error == false) {
Alert.show("Registro deletado com sucesso", "Confirmação");
} else {
Alert.show(obj.msg, "Erro");
}
init();
});
grid.enabled = true;
}
}
/ ** *呼叫删除记录的请求 * / public function deleteRecord(event:Event):void { Alert.show(“EstaoperaçãoNóopoderásersedesfeita。\ nDeseja mesmo remover o status \”“+ grid.selectedItem.displayName +”\“?”,“Confirmação”,Alert.YES | Alert.NO,this,actionDeleteRecord); }
public function onModuleReady(event:ModuleEvent):void
{
var loader:ModuleLoader = event.target as ModuleLoader;
var m:* = loader.child as IModule;
if( m ) m.addEventListener( Event.RENDER, function runModule(e:Event):void{
m.setId(grid.selectedItem.id);
m.window = win;
m.removeEventListener( Event.RENDER, runModule );
});
}; [/代码]
我需要使用colorProvider中存在的颜色值来设置行的背景。
对不起我的无知,这是我的第一个使用flex的项目。
感谢的!
答案 0 :(得分:0)
解决方案是创建一个扩展DataGrid的类并覆盖drawRowBackground方法,该方法负责在行项后面绘制一个彩色矩形。
The drawRowBackground method传递一个默认颜色,以及当前数据项的索引,因此您可以检索当前项,从中获取自定义颜色属性,并将该颜色传递给super.drawRowBackground ()打电话。
override protected function drawRowBackground(s:Sprite, rowIndex:int,
y:Number, height:Number,
color:uint, dataIndex:int):void
{
if (dataIndex < dataProvider.length && dataProvider[dataIndex])
{
color = dataProvider[dataIndex].color;
}
super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
}