6 Replies Latest reply on May 20, 2008 5:00 AM by laurent_pinson

    Expand a certain amount of levels in the tree of an AdvancedDataGrid

    John Cambridge
      I'm using an AdvancedDataGrid, and I want to expand a certain amount of levels in the tree. Suggestions?
        • 1. Re: Expand a certain amount of levels in the tree of an AdvancedDataGrid
          ericbelair Level 1
          Here's how I do it:

          private function expandToLevel(maximumDepth:int=0):void
          {
          // Create a Hierarchical View Cursor to loop through the data provider items
          var dataCursor:IHierarchicalCollectionViewCursor = adg.dataProvider.createCursor();

          // Loop through each item (until current is null)
          while (dataCursor.current)
          {
          // If the item is within the maximum depth specified, open the node
          if(dataCursor.currentDepth < maximumDepth)
          {
          adg.dataProvider.openNode(dataCursor.current);
          }

          // Go to the next item in the cursor
          dataCursor.moveNext();
          }

          // Refresh the data provider to properly display the newly opened nodes
          adg.dataProvider.refresh();
          }

          Hope that helps.
          • 2. Re: Expand a certain amount of levels in the tree of an AdvancedDataGrid
            John Cambridge Level 1
            Thank you very much! It's hard to find information on AdvancedDataGrids!
            • 3. Re: Expand a certain amount of levels in the tree of an AdvancedDataGrid
              John Cambridge Level 1
              I'm using this code, but unfortunately it's incredibly slow. In fact, it's so slow that if I run expandToLevel(4) on my data, it causes the flash to timeout and automatically kill the application.

              I'm trying to display a Please Wait message while this code is executing. I basically just disable everything else and show a Label that says Please Wait. However, the message never shows up. I assume this is because the window is not repainting before it goes into this loop.

              Is there any way I can force it to repaint, or are there any other good solutions to this problem?

              Thanks!
              • 4. Re: Expand a certain amount of levels in the tree of an AdvancedDataGrid
                Sreenivas R Adobe Employee
                Try with this.

                private function expandToLevel(maximumDepth:int=0):void
                {
                // Create a Hierarchical View Cursor to loop through the data provider items

                var dataCursor:IHierarchicalCollectionViewCursor = adg.dataProvider.createCursor();

                var nodesToOpen:Array = [];
                // Loop through each item (until current is null)
                while (dataCursor.current)
                {
                // If the item is within the maximum depth specified, open the node
                if(dataCursor.currentDepth < maximumDepth)
                {
                nodesToOpen.push(dataCursor.current);
                }

                // Go to the next item in the cursor
                dataCursor.moveNext();
                }

                IHierarchicalCollectionView(adg.dataProvider).openNodes = nodesToOpen;

                // Refresh the data provider to properly display the newly opened nodes
                adg.dataProvider.refresh();
                }

                • 5. Re: Expand a certain amount of levels in the tree of an AdvancedDataGrid
                  John Cambridge Level 1
                  Great suggestion! Storing the objects in an array and then setting openNodes is much faster! There is a bug in your code though. Your code only opens up a max of one level. This is because whenever you call .moveNext(), it moves you to the next open node. Since it doesn't open any nodes until the end, it skips over all the closed nodes. In the previous code that Eric suggested, it didn't have this problem because it would open the previous node before moving to the next one.

                  Here's the fix I'm using (there's probably a better solution, but this is my quick fix):
                  private function expandToLevel(maximumDepth:int=0):void
                  {
                  for (var i:int = 1; i < maximumDepth; i++)
                  {
                  var nodesToOpen:Array = [];
                  var dataCursor:IHierarchicalCollectionViewCursor = aurDataGrid.dataProvider.createCursor();

                  while (dataCursor.current)
                  {
                  // If the item is within the maximum depth specified, open the node
                  if(dataCursor.currentDepth < maximumDepth)
                  nodesToOpen.push(dataCursor.current);

                  // Go to the next item in the cursor
                  dataCursor.moveNext();
                  }
                  IHierarchicalCollectionView(aurDataGrid.dataProvider).openNodes = nodesToOpen;
                  }

                  // Refresh the data provider to properly display the newly opened nodes
                  aurDataGrid.dataProvider.refresh();
                  }
                  • 6. Re: Expand a certain amount of levels in the tree of an AdvancedDataGrid
                    laurent_pinson Level 1
                    thx for this code, it may be what i am looking for