4 Replies Latest reply on Jul 7, 2011 8:40 AM by UbuntuPenguin

    Advanced Data Grid datasource Arraycollection addItem extremly slow

    kingsteff4711

      Hello everyone,

       

      i want to add 2000 items to my existing arraycollection, which is the datasource for the Advanced Data Grid i made.

       

      here is the code:

       

      for(var i:int;i<res.length;i++) {

      var swap:myDataGridObject = incomingdataarray[i];

      datasourcearray.addItemAt(swap,i);

      }  

       

      it takes about 2 minutes .... thats very slow, thinking of one is waiting 2 minutes every time he expanded a node in the tree.

       

      as a solution i tryied to do it like this:

       

      datasourcearray = new ArrayCollection( ObjectUtil.copy( incomingdataarray.source ) as Array );

       

      the result is that it is actually working, but i can not expand my treenodes any longer. there seemed to be no items in there.

      adatagrid.valdiatednow() also has no effect.

       

      perhaps anybody came across the same thing an can help me out

       

      thanks

       

      steff

        • 1. Re: Advanced Data Grid datasource Arraycollection addItem extremly slow
          UbuntuPenguin Level 4

          Can you go into a little more detail about what you are trying to do.  You said that you are adding items to an arraycollection but in the code you show, it appears you are trying to do something else, like adding items to the front of the arraycollection in the order they were received.  Could you clarify what you mean when you say " there seemed to be no items in there".  Was the tree empty, could you not open a node, did a node disappear ?  As for your first example, everytime you add an item to an arraycollection a CollectionEvent is dispatched notifying the view that the underlying data has changed and that it needs to get to work.  Of course these events have to be processed eating into your performance (I don't know about 2 minutes/0.06 seconds an object though).

           

          You could try invoking disableAutoUpdate on the arraycollection to stop it from yapping everytime an object is added and then invoking enableAutoUpdate when you are done modifying the arraycolletion but of course your view will still have to contend with the 2000 queued updates.  Or you could just work with the source of the array doing something like this.

           

          var oldSource:Array = collection.source;


          ///Add stuff to your oldSource array here

           

          collection.refresh;

           

          That way the view will get one CollectionEvent.

          • 2. Re: Advanced Data Grid datasource Arraycollection addItem extremly slow
            kingsteff4711 Level 1

            Hi,

             

            first, thank u for your fast answer. I try to add Items to a ArrayCollection which is the dataprovider from my ADG.

             

            i did this in this way:

             

            for(var i:int;i<incomingDataArray.length;i++) {

            var swap:myObject = incomingDataArray[i];

            datasourceAC.addItemAt(swap,i);

            }

             

            i get the data from another method in form of a array collection, which contains many of the myObjects Elements.

            The datasourceAC is the provider as mentioned above. the only way it works for me to add the items to the dataSourceAC and the ADG beeing updated in the

            correct way is this one. but its very slow....

             

            now i tried your hint like this:

             

            var sourceArray:Array = datasourceAC.source;

            for(var i:int;i<incomingDataArray.length;i++) {

            var swap:myObject = incomingDataArray[i];

            sourceArray.push(swap);

            datasourceAC.refresh();

             

            the result is that the nodes are loaded an displayed but i can not expand them any longer. they seemed to be empty.

            as i traced that problem a little closer i realized that my groupingfunction isnt called either.... i dont know wh y;(

             

            hope that explains everything

             

            thanks for help

             

            steffan

            • 3. Re: Advanced Data Grid datasource Arraycollection addItem extremly slow
              kokorito Level 4

              cant you use addAll or splice and add them all in one go rather than 1 at a time in a loop?

              • 4. Re: Advanced Data Grid datasource Arraycollection addItem extremly slow
                UbuntuPenguin Level 4

                Or he could use the concat function.  There are MANY underrated array functions that make life easier.

                 

                As far as the tree nodes misbehaving I would have to have more code and probably more time since I haven't worked with an ADG.  I have worked with trees in the past, what I remember is that your objects should implement IUID ( not only trees, but anytime an itemrenderer is used just to make your life easier ) and ITreeDataDescriptor2(?).  That was a long time ago, but it might be worth looking into.