Question

Is it possible to change the folder icon of a tree column in an AdvancedDataGrid based on the data of that row?

I have an AdvancedDataGrid that is displaying HierarchicalData (from XML data) in a tree format. I want to display a different icon for the folder icon based on the XML data for each row. The only obvious way to change the folder icons at all is to set the folderOpenIcon and folderClosedIcon properties of my AdvancedDataGrid, but that sets the folder icon for all rows. I tried using the AdvancedDataGrid function "setItemIcon", but that doesn't seem to work.

I have some ColumnRenderers in this AdvancedDataGrid that display different icons in other columns based on the row data, but I haven't found a way to do this with the main tree column. I'm guessing it would be similar to using a ColumnRenderer, but maybe using something like a GroupItemRenderer.

Was it helpful?

Solution

This should be possible via an groupIconFunction like this:

<mx:AdvancedDataGrid groupIconFunction="getGroupIcon">
   <mx:columns>
       <mx:AdvancedDataGridColumn headerText="Name" dataField="name"/>
   </mx:columns>
</mx:AdvancedDataGrid>

<fx:Script>

[Embed(source='/assets/company.png')]
private static const COMPANY_ICON: Class;

[Embed(source='/assets/customer.png')]
private static const CUSTOMER_ICON: Class;

private function getGroupIcon(item:Object,depth:int):Class
{
    if (item is Company)
        return COMPANY_ICON;
    if (item is Customer)
        return CUSTOMER_ICON;
    // null = default icon
    return null;
}

</fx:Script>

There is also an example in Adobe's Flex online reference which demonstrates how to use the groupIconFunction and groupLabelFunction properties.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top