How to refresh the item renderer of a flex datagrid after sorting

actionscript-3apache-flex

I am using an itemRenderer for a column of datagird (to display the data in form a hyperlink in a certain fashion) inside action script.

Everything works fine until I Sort any column of datagrid! When I do sort and I click the item inside this column it passes the wrong data to the function onCustomLink. I guess it is passing the old data based on original index of itemRenderer. Somehow itemRenderer class (CustomLinkRenderer) is not refreshing its data!

I tried putting invalidateDisplayList, ValidateNow() on headerRelease of the datagrid but no help! I even tried refreshing the dataprovider on headerRelease() but no help…

Could someone point what I should do to refresh the itemRenderer instances created for this datagrid on headerRelease event?

private var _col1:DataGridColumn;
var rendr1:ClassFactory = new ClassFactory(CustomLinkRenderer);
 _col1.dataField = 'emp_name'; 
 rendr1.properties = {SelCustomLinkName: 'emp_name'};   
                                _col1.itemRenderer = rendr1;
this.addEventListener(CustomLinkRendererEvent.CUSTOM_LINK_RENDERER_EVENT,onCustomLink);

Thanks…

Best Answer

I'm guessing a bit. I'm unclear exactly where the code snippet you provided shows up in your code.

But, it sounds to me like your itemRenderer is not properly updating itself. The itemRenderer should listen to the dataChange event; which should be called when the dataProvider is sorted. Inside your renderer do something like this:

this.addEventListener('dataChange',onDataChange);

public function onDataChange(event:Event):void{
 // do stuff to update the itemRenderer's display
}