开发者

how to refresh the item renderer of a flex datagrid after sorting?

开发者 https://www.devze.com 2023-03-09 06:30 出处:网络
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.

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 datapr开发者_如何转开发ovider 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...


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
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消