PDA

View Full Version : Multiple AdvancedDataGrid under A viewstack cause both to refresh


anupkumarrai
11-16-2008, 04:59 AM
I have a ViewStack which consists of 2 AdvancedDataGrid.
I have 2 buttons which allow selecting these ADGs.
When I load the Flex Application, the first viewStack and its ADG gets loaded.
When I click the second button, I get the second ADG under second view stack loaded.
So far so good.
I have a few Slider and checkbox controls which are attached to filter the ADGs. They call the same filterfunction.
The problem is that I want to control each of the ADGs separately.
When the visible viewstack is second ADG, controls seem to refresh data on both datagrids simultaneously. Even though the call to just one of the ADG refresh is made, it seems to refresh data on both ADGs.
This happens only after the second ADG is views at least once.

This makes the app terrible slow.

Can I have just one of the datagrid refresh at a time? Currently the shifting between tabs/viewstacks is very fast, but the slider-change -> data update is very slow.

I can live with the tab switch delay.
I tried
A) having 2 separate filterfuntions.
B) Dataprovider same and different
C) Used both tabnavigator and viewstack
D) create ADGs dynamically.
E) Set the otherADG null when one is selected and vice-versa

All produces no diffrenece. Same result.


Any help is appreciated.
-Anup

Sly_cardinal
11-16-2008, 11:33 PM
Are your AdvancedDataGrids using different ArrayCollections as their dataProvider properties?

If two datagrids are using the same ArrayCollection then a change made by one datagrid will be mirrored by the other datagrid.

anupkumarrai
11-17-2008, 12:25 AM
Thanks for sending me in the right direction. Even though I was using a different ArrayCollection as a copy, it wasn't a deep copy. Thus it would reference back to the same old ArrayCollection.

Now I am using a copy in this form

private function getCopy(value:ArrayCollection):ArrayCollection{
var buffer:ByteArray = new ByteArray();
buffer.writeObject(value);
buffer.position = 0;
var result:Object = buffer.readObject();
return result as ArrayCollection;
}

This works!

What do you think? Is this a right approach?

-Anup

Sly_cardinal
11-17-2008, 12:34 AM
You should just be able to use instantiate a new ArrayCollection from the same Array source. If you are only filtering and sorting the ArrayCollection then this will be fine:


private function getCopy(value:ArrayCollection):ArrayCollection
{
var ac:ArrayCollection = new ArrayCollection(value.source);
return ac;
}


If you are going to add or delete items from the Array then you should duplicate the array beforehand:


private function getCopy(value:ArrayCollection):ArrayCollection
{
var array:Array = value.source.concat(); // Duplicates the array.
var ac:ArrayCollection = new ArrayCollection(array);
return ac;
}

anupkumarrai
11-17-2008, 03:01 AM
Thanks!

The second one did work.

-Anup