Use styleFunction to apply style to AdvancedDataGrid based on conditions
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.ArrayCollection;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
[Bindable]
private var dpADG:ArrayCollection = new ArrayCollection([
{Artist:'A', Album:'aa', Price:1.99},
{Artist:'J', Album:'jj', Price:1.99},
{Artist:'K', Album:'kk', Price:1.99}
]);
protected var artistName:String;
public function setArtistName(event:Event):void
{
artistName=Button(event.currentTarget).label;
myADG.invalidateList();
}
public function myStyleFunc(data:Object,col:AdvancedDataGridColumn):Object
{
if (data["Artist"] == artistName)
return {color:0xFF0000};
return null;
}
</mx:Script>
<mx:AdvancedDataGrid id="myADG" width="100%" height="100%" dataProvider="{dpADG}" styleFunction="myStyleFunc">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Artist" />
<mx:AdvancedDataGridColumn dataField="Album" />
<mx:AdvancedDataGridColumn dataField="Price" />
</mx:columns>
</mx:AdvancedDataGrid>
<mx:HBox>
<mx:Button label="A" click="setArtistName(event);" />
<mx:Button label="J" click="setArtistName(event);" />
<mx:Button label="K" click="setArtistName(event);" />
</mx:HBox>
</mx:Application>
Related examples in the same category