Flex中AdvancedDataGrid上的TreeColumn的ItemRenderer

时间:2010-04-14 15:42:59

标签: flex itemrenderer advanceddatagrid

是否可以将渲染器用于高级数据网格中的树列并仍然保持层次结构功能?如果我使用渲染器提供程序,则会丢失树下拉列表的箭头。我想保留树功能并更改列的显示。(而不仅仅是文件夹图像)

<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>

1 个答案:

答案 0 :(得分:10)

以下是我为实现这一目标所做的工作:

  1. 创建一个扩展AdvancedDataGridGroupItemRenderer
  2. 的类
  3. 在新类中覆盖updateDisplayList并执行您需要执行的操作
  4. 将新类分配给AdvancedDataGrid的groupItemRenderer属性
  5. 以下是您的新课程的样子

    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();
            }
        }
    }
    

    然后将此类分配给AdvancedDataGrid的groupItemRenderer属性:

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

    或者,在ActionScript中:

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