我需要以编程方式为spark数据网格设置headerRenderer,因为我需要为它分配一些属性(开始和结束时间)。此数据是从数据库中提取的,需要在加载后分配给此headerrenderer。
虽然以编程方式设置我的itemRenderer没有问题,但我发现找不到为headerRenderer做同样的事情。
这是一段简化的代码:
主要
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
customHeaderColumn.headerRenderer = new ClassFactory(myHeaderRenderer);
customHeaderColumn.itemRenderer = new ClassFactory(myItemRenderer);
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:DataGrid width="100%">
<s:dataProvider>
<s:ArrayList>
<fx:Object name="record"/>
</s:ArrayList>
</s:dataProvider>
<s:columns>
<s:ArrayList>
<s:GridColumn id="customHeaderColumn" headerText="Column 1"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:Button label="change" click="button1_clickHandler(event)"/>
</s:Application>
myItemRenderer
<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
<s:Label top="9" left="7" text="item"/>
</s:GridItemRenderer>
myHeaderRenderer
<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
<s:Label top="9" left="7" text="header"/>
</s:GridItemRenderer>
单击按钮时,您可以看到itemRenderer更改,但headerRenderer保持不变。
答案 0 :(得分:0)
看起来你可以通过执行:
强制它myDataGrid.columnHeaderGroup.layout.clearVirtualLayoutCache();
我从DataGrid.as中复制了这一行set columns方法:
public function set columns(value:IList):void
{
if (setGridProperty("columns", value))
{
if (columnHeaderGroup)
{
columnHeaderGroup.layout.clearVirtualLayoutCache();
columnHeaderGroup.invalidateSize();
columnHeaderGroup.invalidateDisplayList();
}
dispatchChangeEvent("columnsChanged");
}
}