Hi,

I have implemented dynamic grouping in advancedDataGrid . I have
extended the AdvancedDataGridRenderer to provide a menu which gives
options like Dynamic Grouping etc.

The problem is that i am able to group the grid dynamically only
once.It is because of these lines of code :

groupingCollection.source = ICollectionView(grid.dataProvider);  ---
(1)
//
//
grid.dataProvider = groupingCollection;--(2) (This converts the
dataGrid's dataProvider to IHierarchicalCollectionView type and hence
the second time when i click on another column to group it it gives
this error : TypeError: Error #1034: Type Coercion failed: cannot
convert mx.collections::hierarchicalcollectionv...@272e3d1 to
mx.collections.ArrayCollection.

Any help in this regard would be highly appreciated.

Thanks,
Shishir.


Here is the code for the renderer :

package {

import flash.events.MouseEvent;

import mx.collections.ArrayCollection;
import mx.collections.Grouping;
import mx.collections.GroupingCollection;
import mx.collections.GroupingField;
import mx.collections.ICollectionView;
import mx.containers.HBox;
import mx.containers.TitleWindow;
import mx.controls.*;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import
mx.controls.advancedDataGridClasses.AdvancedDataGridHeaderRenderer;
import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;
import mx.events.MenuEvent;
import mx.managers.PopUpManager;

public class MenuHeaderRenderer extends
AdvancedDataGridHeaderRenderer {


   public var restore:Button;
   public var menuBar:HBox;
   public var _gridColumn:AdvancedDataGridColumn;
   public var _grid:AdvancedDataGrid;
   public var menu:PopUpMenuButton;
   public var dataSource:ArrayCollection;
   public var menuData:Array = [label: "Group By", data: "Group By"}];




 //constructor
   public function MenuHeaderRenderer():void
   {
           super();
           this.id="menuHeaderRenderer";
           menu = new PopUpMenuButton();
           menu.x = 1;
           menu.width = 15;
           menu.dataProvider=menuData;
           menu.toolTip = "";

                   //subscribe to the events of interest
           menu.addEventListener
(MenuEvent.ITEM_CLICK,menuOptionHandler);
           addEventListener(MouseEvent.ROLL_OVER,OnMouseRollOver);

   }

     //gets the associated dataGrid column
    private function get gridColumn():AdvancedDataGridColumn{
        if(_gridColumn == null){
           _gridColumn = data as AdvancedDataGridColumn;

      }
        return _gridColumn;
  }

 //gets the associated dataGrid column
    private function get grid():AdvancedDataGrid{
        if(_grid == null){
           _grid = listData.owner as AdvancedDataGrid;
           dataSource = ArrayCollection(grid.dataProvider);
      }
        return _grid;
  }

   //Event Handlers
    //Response to Mouse RollOver event
    private function OnMouseRollOver(event:MouseEvent):void{

        //control the sortable property of the column
        if(event.localX > menu.x + menu.measuredWidth){
            if(gridColumn != null){
                gridColumn.sortable = true;
            }
        }
        else{
            if(gridColumn != null){
                gridColumn.sortable = false;

            }
        }
    }


 //handle the menu options here
 private function menuOptionHandler(event:MenuEvent):void
 {


        var groupingCollection:GroupingCollection = new GroupingCollection();
        var grouping:Grouping = new Grouping();
        var groupingField:GroupingField = new GroupingField
(gridColumn.dataField);
        grouping.fields = new Array();
        ///////Error here //////////
       groupingCollection.source = ICollectionView
(grid.dataProvider); //Causing problem  ---(1)
        grouping.fields.push(groupingField);
        groupingCollection.grouping = grouping;
        groupingCollection.refresh();
        grid.dataProvider = groupingCollection; --(2)--


 }

 override protected function createChildren():void {
   super.createChildren();
   addChild(menu);

   }

   override protected function
updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
   super.updateDisplayList(unscaledWidth, unscaledHeight);
   menu.setActualSize(menu.getExplicitOrMeasuredWidth(),
                               menu.getExplicitOrMeasuredHeight());
   }
}

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to