2
votes

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...

2
Show more code. If sorting is the problem then post the sorting code. Also sounds like your renderer is not working right so post that code also.The_asMan
I generally sort the data source(Array collection) manually via Filter function besides depending on the Flex internal sort. Since you are populating the data into component which is then attached to the IList controlled through Item render which obviously leads to issues , main reason may be due to the component complexity.Sabha B

2 Answers

4
votes

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
}
0
votes

Well, your code isn't very clear since you're not specifying which datagrid, the item renderer you're using or how you're actually sorting.

However, I'm fairly sure that your problem is because you're not refreshing your ArrayCollection:

arrayCollection.sort();
arrayCollection.refresh();

The refresh is needed to let the datagrid know to update the item renderers with new data.