Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ItemRenderer for TreeColumn on AdvancedDataGrid in Flex

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>
like image 947
Barrest Avatar asked Dec 29 '22 20:12

Barrest


1 Answers

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);
like image 145
Jeremy Mitchell Avatar answered Jan 06 '23 12:01

Jeremy Mitchell