Search code examples
actionscript-3apache-flexadvanceddatagrid

AdvancedDataGrid : Conditionally change the icon of the leaf node


Introduction: I have a flat ArrayCollection of object's, which i group to create the dataProvider for an AdvancedDataGrid. In this AdvancedDataGrid i have different branches representing different type of tasks. I want to conditionally change the icon for the leaf nodes in the AdvancedDataGrid based on a date field stored in each object.

For this purpose lets say each Task object contains an id and an updatedDate (Representing when the task was last updated). If the task has not been updated in the last five days (updatedDate+5 < today) the icon of that leaf node(Task) should be red, in constrast to the opposite the leaf icon in the AdvancedDatagrid should be green, e.g. like the image below. In this case task 35 has not been updated in the last 5 days, while 13 and 39 have.

enter image description here

Question: How do i change the leaf icons in the ADG based on the updatedDate of the underlying object? I would think that i have to extend AdvancedDataGrid and override some method, but which and how? Any type of guidance for achieving this particular task is much appriciated!

I have seen easy ways of changing the open and closed icons on the web, but no way of conditionally changing an open node's icon :)

Update: After applying @takteek groupIconFunction solution which always returned the same icon:

enter image description here

The problem is that I need the leaf node's icons changed, and not the branches.

SOLVED: Used @takteek's answer, with the exception of using iconFunction instead of groupIconFunction, because i wanted to change the leaf node's icons, and not the groupIcons :)


Solution

  • Your two options are:

    1. Specify agroupIconFunction for the data grid. This gets passed the current item and you return which icon to use, or null to use the default.

    2. Create a subclass of AdvancedDataGrid and override makeListData. This function is responsible for creating the AdvancedDataGridListData object that gets passed to the renderers. You can change the icon and disclosureIcon properties on the list data to what you want. This is probably unnecessary unless you need more control.

    3. Create your own item renderer based on AdvancedDataGridGroupItemRenderer.