Fix for Flex Datagrid caching or repeating data in new rows
I had an odd problem with my Flex datagrid seemingly caching data in its rows. I say, "seemingly," because the Datagrid's dataprovider was accurate, up-to-date, filled with the correct data, but when I removed items from the dataprovider, then added new ones, the datagrid would initially show a row with some data from a previously deleted item.
The Fix
The field that always had the "cached" data was using a custom itemRenderer. My problem stemmed from the fact that I was setting a variable for the renderer in a creationComplete handler:
private function init():void
{
data = value;
notes = (data.hasOwnProperty("notes")) ? data.notes : data.initialInspection.notes;
}
After reading this post at Nabble
http://www.nabble.com/Datagrid-duplicate-row-td21321826.html
I did what I should have done to begin with, which was override the data setter function for the renderer:
override public function set data(value:Object):void
{
if (value != null)
{
super.data = value;
notes = (data.hasOwnProperty("notes")) ? data.notes : data.initialInspection.notes; }
}
Problem solved. Because creationComplete only gets called once, and I'm guessing because of the Datagrid/List optimizations, the data in the renderer was being retained.
