【问题标题】:Is there any way to define a default itemrenderer for flex halo datagrid有没有办法为 flex halo datagrid 定义一个默认的 itemrenderer
【发布时间】:2013-11-12 15:10:05
【问题描述】:

虽然这听起来很容易,但我无法找到解决方案。 我有一个没有定义列的 DataGrid,但有一个 ItemRenderer(在 DataGrid 本身上)。 我希望数据网格在将数据填充到其中时使用此 ItemRenderer。

<mx:DataGrid id="dataGrid" height="100%" width="100%" itemRenderer="my.renderer" />

通过查看 DataGrid 代码,它看起来应该只在预定义的列上。 我发现的唯一解决方法是在填充 dataProvider 后分配 itemRenderer(它会自动创建列)

【问题讨论】:

    标签: apache-flex datagrid itemrenderer


    【解决方案1】:

    ItemRenderer 在列上定义;不在 DataGrid 上,所以我希望您的代码会引发编译器错误。

    itemRenderer 是一个属性,所以不能在 DataGridColumn 上用 CSS 设置。

    但是,MX DataGrid 确实有一个样式名称 defaultDataGridItemRenderer,它应该传递给 GridColumns。您应该能够在 CSS 中设置它并使用它来定义每列的默认 itemRenderer。

    当你终于有了一个 dataProvider 时;您还可以在 ActionScript 中手动创建列,并以这种方式在每列上设置 itemRenderer。

    在发现 defaultDataGridItemRenderer 样式之前,我最初的建议是说可以扩展 DataGridColumn 类以设置默认 itemRenderer 值。但是,在您提供的代码示例中,您没有手动定义列;因此您还必须扩展 DataGrid 才能使用您的自定义列类。

    【讨论】:

    • 感谢您的回答,但 ItemRenderer 可以在 DataGrid 本身上定义(它有效),我没有尝试使用 CSS 设置它(我说 CSS 了吗?)
    • @ofir itemRenderer 不是 MX DataGrid 上的记录属性:help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/… 所以我不知道为什么会这样。
    • 我认为defaultDataGridItemRenderer 是您所需要的;并相应地更新了我的答案。
    【解决方案2】:

    itemRenderer 属性是 ListBase(DataGrid extend ListBase)

    如果您设置了 DataGrid.itemRenderer="mx.controls.TextInput" 和未设置值的列,则 DataGrid 将使用 TextInput 创建项目渲染器和标题渲染器。

    这是 DataGrid 中的源代码

    public function createColumnItemRenderer(c:DataGridColumn, forHeader:Boolean, data:Object):IListItemRenderer
    {
        var factory:IFactory;
    
        // get the factory for the data
        factory = c.getItemRendererFactory(forHeader, data);
        if (!factory)
        {
            if (!data)
                factory = nullItemRenderer;
            if (!factory)
                factory = itemRenderer;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      • 2017-12-05
      • 2011-10-17
      • 2012-02-11
      • 1970-01-01
      相关资源
      最近更新 更多