5 Replies Latest reply on Oct 22, 2007 7:32 AM by ebelair

    Expand One Specific Level of a Multi-Level Advanced DataGrid

    ebelair Level 1
      I have an Advanced DataGrid (ADG) which displays three levels - we'll call them "Parent", "Child", and "Child Detail" - using a HierarchicalData collection which is built from XML from a WebService (see attached code).

      The ADG is generated just as I would like it, and I am able to Expand All levels, as well as Collapse All levels using the expandAll() and collapseAll() methods.

      However, by default, I want the grid to display with the first level ("Parent") as the only open level. I can't seem to find a way to do this, using the existing properties and methods of the ADG class.

      Does anyone have any suggestions?
        • 1. Re: Expand One Specific Level of a Multi-Level Advanced DataGrid
          ebelair Level 1
          Still no luck with this. This is the last piece to my puzzle if anyone can help.
          • 2. Re: Expand One Specific Level of a Multi-Level Advanced DataGrid
            ebelair Level 1
            I found a solution to this, if anyone else out there wants it...though, when used with large amounts of data (I tried this script with a 5 column, 15,000 row grid), it adds time to the rendering of the grid (and sometimes times out) and is not visually pleasing to the eye at times.

            Basically, when the data is loaded, the script calls the expandAll() method to open all nodes, then loops through the openItems array, closing any items do not have a value of "1" for the level where they are (an attribute of the XML node).
            • 3. Expand One Specific Level of a Multi-Level Advanced DataGrid
              ebelair Level 1
              Don't know if anyone out there cares, but I found a better way to do this. I was forced to find a new way because FB3 Beta2 no longer supports the "openItems" propery of mx.controls.AdvancedDataGrid. See attached code for the solution.

              Notes:
              "this" is the ADG as a Flex Component

              • 4. Re: Expand One Specific Level of a Multi-Level Advanced DataGrid
                sameerb Level 1
                Hi,
                You can directly iterate over the items and set the openNodes property in HierarchicalCollectionView. The openNodes property in HierarchicalCollectionView is same as the openItems property in AdvancedDataGrid.

                Here is a sample code -

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical">

                <mx:Script>
                <![CDATA[
                import mx.collections.IViewCursor;
                import mx.collections.ICollectionView;
                import mx.collections.IHierarchicalCollectionView;
                import mx.collections.ArrayCollection;
                import mx.collections.HierarchicalData;

                [Bindable]
                private var fs2:Array =
                [
                {fileName: "utils", children: [
                {fileName: "StringUtil.as12121212121212", Summary:"true", size:"5563 bytes", lastModified:"October 6, 2006", type:"File", attributes:"Read Only"},
                {fileName: "ArrayUtil.as121212121212121", size:"2509 bytes", lastModified:"June 12, 2006", type:"File", attributes:"Read Only"}]},
                {fileName:"accessibility", size:"1724 bytes", lastModified:"October 6, 2006", Summary:"false", children: [
                {fileName:"DataGridAccImpl.as", size:"17045 bytes", lastModified:"November 2, 2006", type:"File", attributes:"Read Only"},
                {fileName:"AccImpl.as", Summary:"true", size:"7263 bytes", lastModified:"June 1, 2006", type:"File", attributes:"Read Only"}]},
                {fileName: "controls", children: [
                {fileName: "DataGrid.as", size:"169825 bytes", lastModified:"December 6, 2006", type:"File", attributes:"Read Only"},
                {fileName: "dataGridClasses", children: [
                {fileName: "DataGridItemRenderer.as", size:"18587 bytes", lastModified:"November 20, 2006", type:"File", attributes:"Read Only"},
                {fileName: "DataGridBase.as", size:"36419 bytes", lastModified:"December 6, 2006", type:"File", attributes:"Read Only"}]}]}

                ];

                private function openRootLevel():void
                {
                var arr:Array = [];
                var coll:ICollectionView = new ArrayCollection(fs2);
                var cursor:IViewCursor = coll.createCursor();
                while (!cursor.afterLast)
                {
                arr.push(cursor.current);
                cursor.moveNext();
                }

                IHierarchicalCollectionView(adg.dataProvider).openNodes = arr;
                }

                ]]>
                </mx:Script>

                <mx:AdvancedDataGrid id="adg" dataProvider="{new HierarchicalData(fs2)}" >
                <mx:columns>
                <mx:AdvancedDataGridColumn dataField="fileName" />
                <mx:AdvancedDataGridColumn dataField="size" />
                <mx:AdvancedDataGridColumn dataField="lastModified" />
                </mx:columns>
                </mx:AdvancedDataGrid>

                <mx:Button label="Open Nodes" click="openRootLevel();" />

                </mx:Application>

                Thanks,
                Sameer
                • 5. Re: Expand One Specific Level of a Multi-Level Advanced DataGrid
                  ebelair Level 1
                  Thank you Sameer. Is there any benefit to the method you provided over the one I entered?