3 Replies Latest reply on Jul 22, 2011 6:31 AM by Karl_Sigiscar_1971

    Convert HierarchicalCollectionView to ArrayCollection

    sw_engr

      I'm trying to retrieve the ArrayCollection data provided to DataGrid and AdvancedDataGrid. While gridID.dataProvider works for flat data, I'm getting coercion error when data is heirarchical. Is there a way to retrieve the original ArrayCollection data? Parsing doesn't seem to work either. TIA!

        • 1. Re: Convert HierarchicalCollectionView to ArrayCollection
          Karl_Sigiscar_1971 Level 3

          Look at the declaration for both classes, they are very different and do not implement the same interfaces nor extend the same superclasses:

           

          public class HierarchicalCollectionView extends EventDispatcher
                                                  implements IHierarchicalCollectionView, IXMLNotifiable


          public class ArrayCollection extends ListCollectionView implements IExternalizable

           

          Since Adobe engineers knew that some people would want to use flat data as a hierarchical data source in an AdvancedDataGrid, they came up with the notion of grouping, which allows you to create a hierarchy from flat data.

          • 2. Re: Convert HierarchicalCollectionView to ArrayCollection
            sw_engr Level 1

            I see. But is there no way to retrieve the same flat data that I defined as source in the GroupingCollection2?

             

             

             

            • 3. Re: Convert HierarchicalCollectionView to ArrayCollection
              Karl_Sigiscar_1971 Level 3

              If you have a GroupingCollection2 instance, you can still retrieve its source afterward by using something like var ac:ArrayCollection = gc.source as ArrayCollection;

               

               

              <mx:AdvancedDataGrid id="myADG"    
                  <mx:dataProvider> 
                    <mx:GroupingCollection2 id="gc" source="{dpFlat}"> 
                      <mx:grouping> 
                        <mx:Grouping> 
                          <mx:GroupingField name="Region"/> 
                          <mx:GroupingField name="Territory"/> 
                        </mx:Grouping> 
                      </mx:grouping> 
                    </mx:GroupingCollection2> 
                  </mx:dataProvider>  
                   
                  <mx:columns> 
                    <mx:AdvancedDataGridColumn dataField="Region"/> 
                    <mx:AdvancedDataGridColumn dataField="Territory"/> 
                    <mx:AdvancedDataGridColumn dataField="Territory_Rep"/> 
                    <mx:AdvancedDataGridColumn dataField="Actual"/> 
                    <mx:AdvancedDataGridColumn dataField="Estimate"/> 
                  </mx:columns> 
                </mx:AdvancedDataGrid>


              In the case of this example from the livedocs, var ac:ArrayCollection = gc.source as ArrayCollection; would return a reference to dpFlat.