views:

218

answers:

1

Hi there! I want to use one data source (e.g. an Array) for multiple Datagrids that have different filterFunctions attached and show different columns. First, I thought I use a very straight forward apporach:

  • create the Array
  • create an ArrayCollection for every DataGrid and set the "source" property to the Array
  • create the DataGrids and set their dataProvider property to its designated ArrayCollection

So now. every ArrayCollection can have its own filterFunction, sort state etc. but there needs to be only one Array with all the data in memory.

Now to the point that totally confused me: As new items are added to the Array, of course no Events are dispatched and I have to call itemUpdated manually on each of the ArrayCollections. While debugging into the code in order to get a deeper understanding for Flex, I tried to figure out, what this misterious "itemUpdated" method does, especially as it notes in the adobe documentation, that, if no "property" is given (e.g. it is null), a simple "refresh()" will occur. I did not find any calls to "refresh()" in the whole debugging (and I went down the framework whole as deep as possible (btw: lots of funny comments right in the code :-) )). The only thing I could find was a CollectionChangeEvent getting dispatched with a PropertyChangeEvent in its "item" property. Which was of the kind "UPDATE" (and not, as I would expect "ADD"). When trying to dispatch that event manually, it never worked (e.g. the datagrid did not update). I know I have to stick with itemUpdated for the moment, but as the dataprovider can get big (in both dimensions), performance does concern me and I wnat to understand what is going on under the hood.

And as expected, no help from adobe :-(

So a big thanks for everyone who read this whole text. And an even bigger THANKS to anyone who answers and gives me the slightes hint in how I can get out of the confusion and understand (if thats possible at all) Fles a little better.

finest of all regards,

herbert

+1  A: 

You have to call ArrayCollection.refresh() for each of your dataProviders to get the dataGrids to show the new changes to the source array.

Robusto
Of course, a simple refresh will always do the trick. But as I have quite some data in that Grid (and yes, I know, paging and stuff) a full refresh will do what it says and recalculate the whole grid, which is totally unnecessary when simply adding one entry. That is the idea behind itemUpdated, as it (if provided with the right parameters) will not lead to a refresh, but fire the proper events. Just compare what happens in the refresh method and in the itemUpdated method. Its not the same.
cboese
It seems to me, that no one really understands whats going behind the scenes of the Flex API when it comes to dataProviders. My initial question pointed to a "refresh()-less" solution in order to get better performance, but as there is no such method, I will accept this answer (in spite of it being incomplete/not what I meant) in order to make that clear for people who find this thread from google and out of fairness, as Rubosto's method will always work (quite "robust" ;-) )
cboese