Sure,
This is the example I'm based on, you can just copy/paste to a new project and 
it should work...

temp1.mxml:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; width="800" 
height="400"
creationComplete="init()">
    <mx:RemoteObject>
    </mx:RemoteObject>
    <mx:Script>
        <![CDATA[
include "general.as"

        ]]>
    </mx:Script>
    <mx:HBox paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" 
width="100%" height="100%" >      
    <mx:AdvancedDataGrid id="resultTBLADG" dataProvider="{ohd}" width="700" 
height="300">
<mx:columns>
            <!-- all we want to display of the object is the name, the ADG will
                take care of displaying the parent child relationship -->
            <mx:AdvancedDataGridColumn dataField="name"/>
        </mx:columns>
    </mx:AdvancedDataGrid>
    </mx:HBox>
</mx:Application>


The ObjectHierarchicalData class exactly as in the link I sent

general.as:

import mx.collections.*;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumnGroup;
import mx.controls.advancedDataGridClasses.AdvancedDataGridRendererProvider;


[Bindable]
private var ohd:ObjectHierarchicalData;
[Bindable]
private var ohdTHeader:ObjectHierarchicalData;
[Bindable]
private var hCollView:HierarchicalCollectionView;

/* here's the huge object that we're going to use to populate our
ObjectHierarchicalData object */
private var largeObject:Object =
[
{ id:"1", "name":"Misc", "type":"parent","quantity":"32", "parentTask":"0"},
{id:"2", "name":"Clean the kitchen", "type":"parent", "parentTask":"0"},
{id:"3", "name":"Pay the bills", "type":"parent", "parentTask":"0"},
{id:"4", "name":"Paint the shed", "type":"parent", "parentTask":"1"},
{id:"5", "name":"Get ready for party", "type":"parent","parentTask":"1"},
{id:"6", "name":"Do the dishes", "type":"child","op1":"1", 
"op2":"2","parentTask":"2"},
{id:"7", "name":"Take out trash", "type":"child", "op1":"11","parentTask":"2"},
{id:"8", "name":"Gas Bill", "type":"child", "op3":23,"parentTask":"3"},
{id:"9", "name":"Registration", "type":"child", "op1":"2","parentTask":"3"},
{id:"10", "name":"Fix the car", "type":"parent", "parentTask":"0"},
{id:"11", "name":"New tires", "type":"child","op4":14,"op1":"3" 
,"parentTask":"10"},
{id:"12", "name":"Emissions test", "type":"child","op1":"4", "parentTask":"10"},
{id:"13", "name":"Get new paint", "type":"child","quantity":"33::44","op1":"5", 
"parentTask":"4"},
{id:"14", "name":"Buy brushes", "type":"child", 
"op1":"6","quantity":"32::42","revenue":"rev","sale":"sal","parentTask":"4"},
{id:"15", "name":"Buy Drinks", "type":"child","op1":"7", "parentTask":"5"},
{id:"16", "name":"clean living room", "type":"child","op1":"8", 
"parentTask":"5"},
{id:"17", "name":"finish invitations", 
"type":"parent","op1":"9","parentTask":"5"},{"id":"18", "name":"sub finish", 
"type":"parent","parentTask":"17"},{"id":"19", "name":"sub sub finish", 
"type":"child","parentTask":"18"}];

private var columns:ArrayCollection = new ArrayCollection();


public var headerObj:Object=
[
{id:1,name:"Africa",type:"parent" ,parentTask:"0"},
{id:2,name:"somalia",type:"parent", parentTask:"1"},
{id:3,name:"Macro",type:"parent", parentTask:"1"},
{id:4,name:"op1",type:"child",parentTask:"2"},
{id:4,name:"op2",type:"child",parentTask:"2"},
{id:5,name:"Europe",type:"parent" ,parentTask:"0"},
{id:6,name:"Itly",type:"parent", parentTask:"5"},
{id:7,name:"Japan",type:"parent", parentTask:"5"},
{id:8,name:"op3",type:"child", parentTask:"6"},
{id:9,name:"op4",type:"child", parentTask:"6"},
{id:10,name:"op5",type:"child", parentTask:"7"}
];

private var colGroup:AdvancedDataGridColumnGroup;

private var columnGroup2:AdvancedDataGridColumnGroup;

public var colsArray:Array=[];


private var columnGroup3:AdvancedDataGridColumnGroup;

[Bindable]
private var flag:Boolean = false;

private function buildHeader():void
{
if(!flag){
flag = true;
var advancedDGCol:AdvancedDataGridColumn = new AdvancedDataGridColumn();
ohdTHeader = new ObjectHierarchicalData(headerObj);
resultTBLADG.expandAll();
var colsArray1:Array=[];
hCollView = new HierarchicalCollectionView(ohdTHeader);
advancedDGCol.dataField = "name";
advancedDGCol.width=300;
advancedDGCol.headerText='';
colsArray.push(advancedDGCol);
for each(var hObj:Object in headerObj)
{ 
if(hObj.parentTask=="0")
{
var 
children:ICollectionView=hCollView.getChildren(hCollView.source.getData({id:hObj.id}));
var cursor:IViewCursor=children.createCursor();
colGroup = new AdvancedDataGridColumnGroup();
colGroup.headerText = hObj.name;
prepareColumns(cursor,colGroup);
colsArray.push(colGroup);
}

}

this.resultTBLADG.groupedColumns=colsArray;
this.resultTBLADG.validateNow();
                                // here I load the Item renderer
                                var rendererProviders:Array = new Array();
                                rendererProviders = setRendererProvider();      
                                
                                for each(var 
Item:AdvancedDataGridRendererProvider in rendererProviders){
                                        
this.resultTBLADG.rendererProviders.push(Item);
                                }
}
}
private function 
prepareColumns(cursor:IViewCursor,columnGroup:AdvancedDataGridColumnGroup):void
{

while(!cursor.afterLast)
{
var node:Object = cursor.current;

if(node.type=="parent")
{
var columnGroup2:AdvancedDataGridColumnGroup= new AdvancedDataGridColumnGroup();
columnGroup2.headerText = node.name;
columnGroup.children.push(columnGroup2);
var 
children:ICollectionView=hCollView.getChildren(hCollView.source.getData({id:node.id}));
var cursor1:IViewCursor=children.createCursor();
prepareColumns(cursor1,columnGroup2);
}
else
{
var childColumn:AdvancedDataGridColumn=new AdvancedDataGridColumn();
childColumn.headerText = node.name;
childColumn.dataField = node.name;
columnGroup.children.push(childColumn);
}
cursor.moveNext();
}
}

private function init():void
{
ohd = new ObjectHierarchicalData(largeObject);
resultTBLADG.dataProvider = ohd;
var test:Array = resultTBLADG.dataProvider as Array;
buildHeader();
}

        private function setRendererProvider():Array{
                                columns.addItem("name");
                                columns.addItem("op1");
                                columns.addItem("op2");
                                columns.addItem("op3");
                                columns.addItem("op4");
                                columns.addItem("op5");
                                var 
rendererProvider:AdvancedDataGridRendererProvider;
                                var rendererProviders:Array = new Array();
                                for (var i:int = 0; i < columns.length; i++){
                                        var colName:String = 
columns.getItemAt(i) as String;
                                                rendererProvider = new 
AdvancedDataGridRendererProvider();
                                                rendererProvider.columnIndex=i; 
                                        
                                                var renderer_:IFactory= new 
ClassFactory(ItemRenderer);
                                                // Sending variables to the 
renderer constructor
//                                              (renderer_ as 
ClassFactory).properties = {tableDataProvider_:tableDataProvider};
                                                rendererProvider.renderer= 
renderer_; 
                                                
rendererProvider.dataField=colName;
                                                
rendererProviders.push(rendererProvider);
                                }
                                        return rendererProviders;
                                }




The ItemRenderer:

package
{
        
        import flash.display.*;
        import flash.events.MouseEvent;
        
        import mx.collections.*;
        import mx.containers.HBox;
        import mx.controls.AdvancedDataGrid;
        import mx.controls.Label;
        import mx.controls.dataGridClasses.DataGridListData;
        import mx.controls.listClasses.BaseListData;
        import mx.controls.listClasses.IDropInListItemRenderer;
        import mx.events.*;
        import mx.collections.GroupingCollection;
        import mx.collections.IHierarchicalCollectionView;
        import mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer;
        import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;
        
        public class ItemRenderer extends AdvancedDataGridItemRenderer 
implements IDropInListItemRenderer{
           private var _listData:DataGridListData;
                private var updatedDP:ArrayCollection;
                public var adg:AdvancedDataGrid=new AdvancedDataGrid();
                private var ohd:ObjectHierarchicalData; 
           public function ItemRenderer():void{
                        
                        super();
                
                }
        
                override public function set data(value:Object):void {
                var sp:String; 
               super.data = value;
                        if (this.listData)
                                {
                                //  get the owner AdvnacedDataGrid
                                var listOwner:AdvancedDataGrid = 
AdvancedDataGrid(this.listData.owner);  
                            //the default row
                            this.background = false;
                            this.alpha = 0;
                            this.backgroundColor = 0xFFFFFF;
                            if (listData!=null && data != null)
                             { 
                                        this.background = true;
                                        this.backgroundColor = 0xFFB6B6;
                                }
                                // fetch the children of the selected item
                        var childCol:ICollectionView = 
IHierarchicalCollectionView(listOwner.dataProvider).getChildren(value);
                         }       
             }
                override public function get data():Object {
            return super.data;
        }            
                        
//        public function get listData():BaseListData
//        {
//            return _listData;
//        }
//
//        public function set listData(value:BaseListData):void
//        {
//             _listData = DataGridListData(value);
//        } 
        
     
//              override protected function commitProperties():void{
//                      super.commitProperties();
//              }

        }
}


Thats it.

If you run it, you will see a TreeGreed,

If you remark the following lines the ItemRenderer should be disabled and the 
Tree will be revealed:

var rendererProviders:Array = new Array();
rendererProviders = setRendererProvider();                                      
for each(var Item:AdvancedDataGridRendererProvider in rendererProviders){
        this.resultTBLADG.rendererProviders.push(Item);
}


Just make a new project and copy it, then I think you will understand better.

I must use this kind of flat data structure

Thanks a lot


--- In [email protected], "Gregor Kiddie" <gkid...@...> wrote:
>
>  Looking at the renderers source, it is a bit manky internally, though
> what you've posted shouldn't cause too many problems. Is your renderer
> doing anything else? Can you post the whole class?
> 
>  
> 
> Gk.
> 
> Gregor Kiddie
> Senior Developer
> INPS
> 
> Tel:       01382 564343
> 
> Registered address: The Bread Factory, 1a Broughton Street, London SW8
> 3QJ
> 
> Registered Number: 1788577
> 
> Registered in the UK
> 
> Visit our Internet Web site at www.inps.co.uk
> <blocked::http://www.inps.co.uk/> 
> 
> The information in this internet email is confidential and is intended
> solely for the addressee. Access, copying or re-use of information in it
> by anyone else is not authorised. Any views or opinions presented are
> solely those of the author and do not necessarily represent those of
> INPS or any of its affiliates. If you are not the intended recipient
> please contact is.helpd...@...
> 
> ________________________________
> 
> From: [email protected] [mailto:[email protected]] On
> Behalf Of yossi.baram
> Sent: 23 March 2009 09:57
> To: [email protected]
> Subject: [flexcoders] Re: Using ItemRenderer with IHierarchicalData
> DataProvider
> 
>  
> 
> The link I sent may be incorrect,
> look at http://inovativeflexdevolopment.blogspot.com/
> <http://inovativeflexdevolopment.blogspot.com/> 
> (Flex3 Dynamic population of data in Advanced datagrid with customn
> header...) example
> 
> --- In [email protected] <mailto:flexcoders%40yahoogroups.com>
> , "yossi.baram" <yossi.baram@> wrote:
> >
> > It make sense what you asked,
> > Yes it looks good, with hierarchy, when I eliminate the Itemrenderer
> call, my data structure is as in the example:
> >
> http://inovativeflexdevolopment.blogspot.com/2008/07/flex3-dynamic-popul
> ation-of
> <http://inovativeflexdevolopment.blogspot.com/2008/07/flex3-dynamic-popu
> lation-of> \-data-in.html
> > 
> > I am building a flat data (a list of rows) with parentId and type
> (child/parent) in my java server using blazeds i send it by RemoteObject
> to the Flex app.
> > Then I use;
> > ohd = new ObjectHierarchicalData(rows);
> > adg.dataProvider = ohd;
> > 
> > If I dont use the Itemrenderer the Treegrid looks good with all data
> and correct hierarchy,
> > 
> > Please advise if you need some thing else,
> > 
> > Thanks for your time :)
> > 
> > 
> > --- In [email protected]
> <mailto:flexcoders%40yahoogroups.com> , "Gregor Kiddie" <gkiddie@>
> wrote:
> > >
> > > Not to be funny, but does the structure look right when you aren't
> using
> > > a custom renderer? I.e. is your data correct?
> > > 
> > > 
> > > 
> > > Gk.
> > > 
> > > Gregor Kiddie
> > > Senior Developer
> > > INPS
> > > 
> > > Tel: 01382 564343
> > > 
> > > Registered address: The Bread Factory, 1a Broughton Street, London
> SW8
> > > 3QJ
> > > 
> > > Registered Number: 1788577
> > > 
> > > Registered in the UK
> > > 
> > > Visit our Internet Web site at www.inps.co.uk
> > > <blocked::http://www.inps.co.uk/ <http://www.inps.co.uk/> > 
> > > 
> > > The information in this internet email is confidential and is
> intended
> > > solely for the addressee. Access, copying or re-use of information
> in it
> > > by anyone else is not authorised. Any views or opinions presented
> are
> > > solely those of the author and do not necessarily represent those of
> > > INPS or any of its affiliates. If you are not the intended recipient
> > > please contact is.helpdesk@
> > > 
> > > ________________________________
> > > 
> > > From: [email protected]
> <mailto:flexcoders%40yahoogroups.com>
> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
> ] On
> > > Behalf Of yossi.baram
> > > Sent: 23 March 2009 09:30
> > > To: [email protected] <mailto:flexcoders%40yahoogroups.com>
> 
> > > Subject: [flexcoders] Re: Using ItemRenderer with IHierarchicalData
> > > DataProvider
> > > 
> > > 
> > > 
> > > Thanks,
> > > Well, I tried extending AdvancedDataGridItemRenderer &
> > > IDropInListItemRenderer
> > > 
> > > and my set data I'm overriding:
> > > override public function set data(value:Object):void {
> > > 
> > > super.data = value;
> > > if (this.listData)
> > > {
> > > // get the owner AdvnacedDataGrid
> > > var listOwner:AdvancedDataGrid =
> AdvancedDataGrid(this.listData.owner); 
> > > if (listData!=null && data != null)
> > > { 
> > > this.background = true;
> > > this.backgroundColor = 0xFFB6B6;
> > > }
> > > } 
> > > }
> > > 
> > > As you can see for the example its just should paint the rows.
> > > 
> > > But still the data is flat I cannot see child1 as the parent :(((
> > > 
> > > can you give me simple example how should set data() should look
> like to
> > > allow me manipulation on the data but still preserve the hierarchy?
> > > 
> > > I tried many things but nothing
> > > 
> > > Thanks
> > >
> >
>


Reply via email to