views:

454

answers:

2

I have a grid filled with >1000 datasets. one column uses a custom itemRenderer which is used to display the value of a foreign key.

All the datasets which are displayed without scrolling are displayed with the right information. But when it comes to scrolling, some datasets will have displayed the wrong value in the itemRenderer. As far as I have understood this, it is because of the reuse of itemRenderers.

But as great as reusing might be, displaying the wrong information cannot be the result. So how do I get rid of this problem?

EDIT: I have managed to get rid of this problem, but I will post some code anyway to point my plan:

<?xml version="1.0" encoding="utf-8"?>

<mx:Script>
    <![CDATA[
        private var dataAccess : DataAccess = DataAccess.getInstance();
        private var foreign : ArrayCollection = new ArrayCollection();

        private function onCreationComplete() : void
        {

            dataAccess.service.getForeignDatasets.addEventListener("result", onGetForeignDatasets);
            dataAccess.service.getForeignDatasets();
        }

        private function onGetForeignDatasets(event : ResultEvent) : void
        {
            foreign = event.result as ArrayCollection;  
            preSelect();
        }   

        //gets the entry from the foreign entity which matches 
        //the foreign key in this.data
        private function preSelect() : void
        {
            for each(var obj : Object in foreign)
                {
                    if(obj.id == data.foreignKey))
                    {
                        value.text = obj.name;
                        return;
                    }
                }

            value.text = "";    
        }

        private function onDataChange() : void
        {
            preSelect();
        }       
    ]]>
</mx:Script>

I left all the uneccessary code...

The code above works and resolves the problem of displaying wrong data.

Any other idea to implement this functionality?

A: 

This happens if your item renderer caches information in private variables (or anywhere else really). An item render gets it's data through the "data" property. It should not use any data not within the "data" property. If you absolutely have to reach outside to get other data (which you really shouldn't do), then make sure you invalidate that data whenever the data property changes (override data to mark a changed flag and then call super.data).

If this doesn't fix your problem, post your item renderer code.

Sam
A: 

Hmm, sounds verisimilar .. but if the way I'm doing this is wrong, whats the right way?

a sample scenario:

lets have two tables..

t1 with id, name and t2 with a foreign reference on t1.id. i want to display t2 in a datagrid, but the column which holds the foreign key (on t1.id) should not display the id, but t1.name.

so i make a second request on t1, and iterate through the datasets until t1.id matches the foreign key in my itemRenderer. so the t1.name is displayed.

i hope i explained my plan understandable ^^

Thomas
I don't really follow. Can you post your itemRenderer code, if possible only the relevant portions. Please do so by editing your original question. Adding an answer of your own gets confusing quickly since answers are sorted by votes and not time. Stack Overflow isn't a forum. It can be a bit confusing at first.
Sam
sry, my first time posting something here.. i edited my original question
Thomas