ItemRenderer for TreeColumn on AdvancedDataGrid in Flex

Barrest picture Barrest · Apr 14, 2010 · Viewed 7.9k times · Source

Is it possible to use a renderer for for a treecolumn in an advanceddatagrid and still keep the hierarchal functionality? If I use a renderer provider I lose the the arrow for the tree dropdown. I want to keep the tree functionality and change the display of the column.(and not just the folder image)

<mx:AdvancedDataGridRendererProvider column="{titleCol}" depth="1"
        renderer="com.something.titleColumnRenderer"/>

titleColumnRenderer:

<mx:VBox width="100%" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Label id="titleLabel" textAlign="center" text="sometext" width="100"/></mx:VBox>

Answer

Jeremy Mitchell picture Jeremy Mitchell · Apr 15, 2010

Here's what I did to accomplish this:

  1. Create a class that extends AdvancedDataGridGroupItemRenderer
  2. In the new class override updateDisplayList and do what you need to do
  3. Assign the new class to the groupItemRenderer property of the AdvancedDataGrid

Here's what your new class might look like

public class CustomGroupRenderer extends AdvancedDataGridGroupItemRenderer
{
    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
        super.updateDisplayList(unscaledWidth, unscaledHeight);

        var listData:AdvancedDataGridListData = listData as AdvancedDataGridListData;
        var advancedDataGrid:AdvancedDataGridDataGrid = listData.owner as AdvancedDataGrid;

        var cellBackgroundColor:uint = 0xFF0000;

        var g:Graphics = graphics;
        g.clear();

        if (!advancedDataGrid.isItemSelected(data) && !advancedDataGrid.isItemHighlighted(data))
        {
            g.beginFill(cellBackgroundColor);
            g.drawRect(0, 0, unscaledWidth, unscaledHeight);
            g.endFill();
        }
    }
}

And then assign this class to the groupItemRenderer property of the AdvancedDataGrid:

<mx:AdvancedDataGrid groupItemRenderer="com.whereever.CustomGroupRenderer"/>

Or, in ActionScript:

myAdvancedDataGrid.groupItemRenderer = new ClassFactory(com.whereever.CustomGroupRenderer);