03 October 2008

Solution to Flex itemRenderer Recycling

Thanks to a friend, the solution to the itemRenderer recycling issue has been found. In the event handler for the button click, set a custom property on the datagrid's selectedItem,

dgMyGrid.selectedItem.UploadFileName = "myFile.jpg";

The custom property in this case is the UploadFileName. Also note that the data object, which would contain the row's values, is out of scope here. Perhaps this is because we're calling the function from inside the itemRenderer. So instead, we use the datagrid. However, the data object has that custom field set anyway so it can be accessed from the itemRenderer.

Then in the itemRenderer, we override the set data function,

override public function set data(value:Object):void {
super.data = value;

if (data.UploadFileName == undefined){
txtPhoto.text = "";
}
else {
if(data.UploadFileName == null || data.UploadFileName == ""){
txtPhoto.text = "";
}
else {
txtPhoto.text = data.UploadFileName;
}
}
}

No comments: