简体   繁体   English

在Flex的AdvancedDataGrid中设置树列的文件夹图标(基于行数据)

[英]Setting the folder icon of a tree column (based on row data) in AdvancedDataGrid in Flex

Is it possible to change the folder icon of a tree column in an AdvancedDataGrid based on the data of that row? 是否可以根据该行的数据来更改AdvancedDataGrid中树列的文件夹图标?

I have an AdvancedDataGrid that is displaying HierarchicalData (from XML data) in a tree format. 我有一个AdvancedDataGrid,它以树格式显示HierarchicalData(来自XML数据)。 I want to display a different icon for the folder icon based on the XML data for each row. 我想基于每一行的XML数据为文件夹图标显示不同的图标。 The only obvious way to change the folder icons at all is to set the folderOpenIcon and folderClosedIcon properties of my AdvancedDataGrid, but that sets the folder icon for all rows. 更改文件夹图标的唯一显而易见的方法是设置AdvancedDataGrid的folderOpenIcon和folderClosedIcon属性,但这将为所有行设置文件夹图标。 I tried using the AdvancedDataGrid function "setItemIcon", but that doesn't seem to work. 我尝试使用AdvancedDataGrid函数“ setItemIcon”,但这似乎不起作用。

I have some ColumnRenderers in this AdvancedDataGrid that display different icons in other columns based on the row data, but I haven't found a way to do this with the main tree column. 我在此AdvancedDataGrid中有一些ColumnRenderers,它们基于行数据在其他列中显示不同的图标,但是我还没有找到一种对主树列执行此操作的方法。 I'm guessing it would be similar to using a ColumnRenderer, but maybe using something like a GroupItemRenderer. 我猜它与使用ColumnRenderer类似,但也许使用类似GroupItemRenderer的东西。

This should be possible via an groupIconFunction like this: 应该可以通过groupIconFunction这样实现:

<mx:AdvancedDataGrid groupIconFunction="getGroupIcon">
   <mx:columns>
       <mx:AdvancedDataGridColumn headerText="Name" dataField="name"/>
   </mx:columns>
</mx:AdvancedDataGrid>

<fx:Script>

[Embed(source='/assets/company.png')]
private static const COMPANY_ICON: Class;

[Embed(source='/assets/customer.png')]
private static const CUSTOMER_ICON: Class;

private function getGroupIcon(item:Object,depth:int):Class
{
    if (item is Company)
        return COMPANY_ICON;
    if (item is Customer)
        return CUSTOMER_ICON;
    // null = default icon
    return null;
}

</fx:Script>

There is also an example in Adobe's Flex online reference which demonstrates how to use the groupIconFunction and groupLabelFunction properties . Adobe的Flex在线参考中还有一个示例,演示了如何使用groupIconFunction和groupLabelFunction属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM