Hello again, I haven't got any response and was just hoping I could entice 
someone to review my question below. 

The code implements a textbook method to update the client model when someone 
changes the text in a spark TextInput located in a header renderer. This works 
fine. I just need to know a textbook method to go the other direction -- that 
is, how to programmatically update the text in the TextInput? I'm sure there's 
some standard way to do this, but I can't figure it out. Any hints much 
appreciated. I've tried to copy all the relevant code below. 

----- Original Message -----

From: modjkl...@comcast.net 
To: "users, apache" <users@flex.apache.org> 
Sent: Saturday, November 29, 2014 7:12:47 PM 
Subject: how to updateDisplayList() in custom headerRenderer? 

I'm using 4.12 SDK and trying to update a headerRenderer that includes a 
TextInput. Things works fine when the component is initialized. But thereafter, 
when I change the model such that the text showing in the TextInput box should 
change, the text doesn't change. 

Can someone help me figure out how to programmatically refresh the header 
renderer TextInput text using function updateCondition() in file MyView.mxml 
below? 

I've tried create a temp IFactory for the header renderer, null the original 
one, then save the temp back to the original, but this didn't work. Also tried 
invalidateDisplayList() on myGrid (didn't work either). 

Here's MyHeaderRenderer.mxml: 

<?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" 
xmlns:itemRenderers="com.example.views.itemRenderers.*"> 

<fx:Script> 
<![CDATA[ 
import mx.collections.ArrayCollection; 
import com.example.views.components.MyGrid; 

public function ti_focusOut():void { 
MyGrid(this.owner['parentDocument']).myCondition=Number(ti.text); 
MyGrid(this.owner['parentDocument']).dispatchEvent(new 
Event("myConditionChanged")); 
} 

override protected function updateDisplayList(unscaledWidth:Number, 
unscaledHeight:Number):void { 
if (this.owner['parentDocument'] && ti && 
MyGrid(this.owner['parentDocument']).myCondition) { 
ti.text=String(MyGrid(this.owner['parentDocument']).myCondition); 
} 
super.updateDisplayList(unscaledWidth,unscaledHeight); 
} 
]]> 
</fx:Script> 
<s:states> 
<s:State name="normal"/> 
</s:states> 
<s:TextInput id="ti" width="40" focusOut="ti_focusOut();"/> 
</s:GridItemRenderer> 


and here's MyGrid.mxml: 

<?xml version="1.0" encoding="utf-8"?> 
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"; 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx"> 

<fx:Metadata> 
[Event(name="myConditionChanged", type="flash.events.Event")] 
</fx:Metadata> 

<fx:Script> 
<![CDATA[ 
... 
[Bindable] private var _myCondition:Number; 
public function set myCondition(value:Number):void { 
_myCondition=value; 
if (grid.columnHeaderGroup) { 
grid.columnHeaderGroup.layout.clearVirtualLayoutCache(); 
grid.columnHeaderGroup.invalidateDisplayList(); 
} 
grid.invalidateDisplayList(); 
} 
[Bindable] public function get myCondition():Number { 
return _myCondition; 
} 
... 
]]> 
</fx:Script> 

<s:DataGrid id="grid"> 
<s:columns> 
<s:ArrayList> 
<s:GridColumn .../> 
<s:GridColumn id="myColumn" dataField="myCond" 
headerRenderer="com.example.views.itemRenderers.MyHeaderRenderer"/> 
<s:GridColumn .../> 
</s:ArrayList> 
</s:columns> 
</s:DataGrid> 
</s:Group> 

and finally, here is MyView.mxml: 

<?xml version="1.0" encoding="utf-8"?> 
<views:View xmlns:fx="http://ns.adobe.com/mxml/2009"; 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" 
xmlns:components="com.example.views.components.*"> 
... 
<fx:Script> 
<![CDATA[ 
private function updateCondition():void { 
myGrid.myCondition=newValue; 
// how to force refresh of TextInput in header renderer with newValue? 
} 
private function onChange():void { 
... 
} 
]]> 
</fx:Script> 
<components:MyGrid id="myGrid" myConditionChanged="onChange();"/> 
... 
</views:View> 

Reply via email to