Kevincosme / flexlib

Automatically exported from code.google.com/p/flexlib
0 stars 0 forks source link

Treegrid not updated when dataprovider changes #15

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. create a [Bindable] var ed:ArrayCollection = new ArrayCollection;
2. Bind the treegrid to {ed}
3. Create a button and add items to ed.

What is the expected output? What do you see instead?
The treegrid should show the new items

What version of the product are you using? On what operating system?
1.6 downloaded today

Please provide any additional information below.
[Bindable]
private var test:ArrayCollection = new ArrayCollection;

private function fill():void{
for (var x:int = 0; x<4; x++){
var ed:Object = new Object;
ed.taskStatus = "niodfhot";
ed.taskId = "34324";
test.addItem(ed);
}

set dataprovider of treegrid to {ed}
create button click that calls fill()
add a datagrid as well to see how it should behave

Original issue reported on code.google.com by vru...@gmail.com on 5 Apr 2007 at 10:49

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by darron.schall on 7 Apr 2007 at 12:03

GoogleCodeExporter commented 8 years ago
At the current moment, when I bind some XML to the TreeGrid, open all the grid's
branches, add a new node anywhere, and attempt to close an item in the TreeGrid
(let's say the root one) a fatal exception occurs.

It complains about an index (the one assigned to the new node) being out of 
bounds
for the TreeGrid's close item cleanup. This is because the TreeGrid wasn't 
updated
when the bound dataProvider's data changed.

Original comment by troy.bin...@gmail.com on 16 Apr 2007 at 8:01

GoogleCodeExporter commented 8 years ago
As a workaround to this you can go into the TreeGrid's set dataProvider method 
and
add to it:

<pre>
// ...Up above is the big if, else if

_rootModel.addEventListener(CollectionEvent.COLLECTION_CHANGE, 
rootModelChangeHandler);
//flag for processing in commitProps
dataProviderChanged = true;
invalidateProperties();
</pre>

And then add somewhere in the file the following method:

<pre>
protected function rootModelChangeHandler(event:Event):void
{
    //dataProviderChanged = true;
    invalidateProperties();
}
</pre>

This is a really bad solution since it will reset the grid when you 
add/remove/update
things from/in your dataprovider. So if the user is scrolled down and you 
change the
dataprovider its going to result in them being scrolled back up to the top 
again.

Original comment by jerry....@gmail.com on 19 Apr 2007 at 5:19

GoogleCodeExporter commented 8 years ago
Opps, didn't mean to leave the dataProviderChanged = true method commented out. 
Here
is the method again:

protected function rootModelChangeHandler(event:Event):void
{
    dataProviderChanged = true;
    invalidateProperties();
}

Original comment by jerry....@gmail.com on 19 Apr 2007 at 5:22

GoogleCodeExporter commented 8 years ago

Original comment by dmcc...@gmail.com on 26 Dec 2007 at 11:44

GoogleCodeExporter commented 8 years ago
Hi there. I changed the workaround a little so it would remember the scroll 
positions
and the Items opened (openItems). Just works for the same dataprovider object 
with
the same uid. But works fine for me.
have a look:
http://deepenvalley.blogspot.com/2008/01/flextreegrid-withdragdrop-for-xml.html

Original comment by crisscro...@googlemail.com on 7 Jan 2008 at 12:39

GoogleCodeExporter commented 8 years ago
Has there been any movement on this issue?  I'm working on some pretty extensive
modifications since my app has a lazy/incrementally loaded dataProvider and 
needs to
be responsive to dataProvider replace/delete/add events.  If someone from the 
project
team is already putting a lot of effort into this, I'll be patient and wait for 
the
next version.  Otherwise, I'll throw my version up for consideration.

Original comment by thelif...@gmail.com on 27 Feb 2008 at 2:11

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Well it doesn't seem like anyone is working on this problem anymore... I did
add crisscross76 code fix for this issue specifically and got it to work. It 
does
have a problem dealing with a tree with more then just one child depth, so I 
modified
the loop that reopens nodes in the commitProperties() function with:

var lastItem:* = null;
for each(var item:* in openItems){
    if (lastItem != null)
    {
        var parent:* = XML(item).parent();
        if (parent == undefined || lastItem == parent) 
        {
            lastItem = item;
            continue;   
        }
    }
    lastItem = item;
    openItemAt(getItemIndex(item),item);
}

This prevents the code from attempting to expand a child node which has already 
been
expanded in the openItemAt recursive call, causing a duplicate child display. 
This
works for a tree with a depth of 3, but I didn't try anything deeper.

BTW crisscross76, I couldn't read your drag/drop fix. Your blog is cutting up 
the code.

Original comment by lcm...@gmail.com on 31 Mar 2008 at 9:05

GoogleCodeExporter commented 8 years ago
Heres a modification to avoid this problem, it's a small workaround not 
completely
tested :

in TreeGrid.as :

/**
     * 
     */
    public function closeAllItems() : void
    {
        for( var i : int = ICollectionView( _displayedModel ).length-1; i >=0; i-- )
        {
            this.closeItemAt( i );
        }   
    }

    /**
     * 
     */
    public function closeItemAt( rowNum : Number, item : Object = null, closeItem :
Boolean = true ) : void
    {
        if( item == null )
            item = ListCollectionView( _displayedModel ).getItemAt( rowNum );

        if( closeItem )
        {
            var uid : String = itemToUID( item );
            delete _openItems[ uid ];
        }

        if( _dataDescriptor.getChildren( item ) )
        {
            // recursively remove the rows that were added for child records
            // but don't remove item from _openItems[] to keep opened items.
            for( var i : int = 0; i < _dataDescriptor.getChildren( item ).length; i++ )
            {
                if( isItemOpen( _dataDescriptor.getChildren( item )[ i ] ) )
                {
                closeItemAt( rowNum, _dataDescriptor.getChildren( item )[ i ], false );
                }

                if(ListCollectionView( _displayedModel ).length > rowNum + 1)
                {
                    ListCollectionView( _displayedModel ).removeItemAt( rowNum + 1 );
                }
            }
         }
    }

Original comment by arabj...@gmail.com on 8 Jul 2009 at 8:59

GoogleCodeExporter commented 8 years ago
Thanks this worked for me!

Original comment by ferzerk...@gmail.com on 1 Sep 2009 at 9:44

GoogleCodeExporter commented 8 years ago
Have this problem been solved?I run into the same problems.My FlexLib version 
is 2.5. And the follow is my source code.

Original comment by shaobin....@gmail.com on 25 Oct 2011 at 11:26

Attachments: