Link to home
Start Free TrialLog in
Avatar of YossiBa
YossiBa

asked on

Seperate Parent Field & Hirarchy Field in AdvancedDataGrid - please help

Hi,
I am creating a TreeGrid using the AdvancedDataGrid in Flex 3.

The function that build my group columns is :

private function setGroupedColumns():void
{


var groupingCollection:GroupingCollection=new GroupingCollection()

var grouping:Grouping=new Grouping()
var groupingField:GroupingField

grouping.fields=new Array()

// Set the parents columns
var parentIds:ArrayCollection = properties.parantIdColumns as
ArrayCollection;

// Setting the Parent field
groupingField=new GroupingField("parent");
grouping.fields.push(groupingField)


groupingCollection.source=ArrayCollection(remoteDP)

groupingCollection.grouping=grouping
groupingCollection.refresh()
myADG.dataProvider=groupingCollection
}


Here I get a Tree and "parent" field as its parent.
If I push more fields to
grouping.fields.push(groupingField)
I get more sub childrens.
Thats not what I need.


How can I set parent field to stay the parent (in the background) but
to set different field(column) to be the hirarchy column (with the
folder icon or arrow).

The parent column should look as a normal column but the hirarchy
will be based on its data. the Tree appearance will be shown in a
different field.

Can I do it?

Thanks

Jo
Avatar of zzynx
zzynx
Flag of Belgium image

Consider this little application.
I think it does what you want. Right?
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
 
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
                  
            [Bindable]
            private var dpFlat:ArrayCollection = new ArrayCollection([
              {Region:"Southwest", Territory:"Arizona", 
                  Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000}, 
              {Region:"Southwest", Territory:"Arizona", 
                  Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000},  
              {Region:"Southwest", Territory:"Central California", 
                  Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000},  
              {Region:"Southwest", Territory:"Nevada", 
                  Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000},  
              {Region:"Southwest", Territory:"Northern California", 
                  Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000}, 
              {Region:"Southwest", Territory:"Northern California", 
                  Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000},  
              {Region:"Southwest", Territory:"Southern California", 
                  Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000}, 
              {Region:"Southwest", Territory:"Southern California", 
                  Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
            ]);
        ]]>
    </mx:Script>
 
    <mx:Panel title="AdvancedDataGrid Control Example"
        height="75%" width="75%" layout="horizontal"
        paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
 
        <mx:AdvancedDataGrid id="myADG" 
            width="100%" height="100%" 
            initialize="gc.refresh();">        
            <mx:dataProvider>
                <mx:GroupingCollection id="gc" source="{dpFlat}">
                    <mx:grouping>
                        <mx:Grouping>
                            <mx:GroupingField name="Region"/>
                            <mx:GroupingField name="Territory"/>
                        </mx:Grouping>
                    </mx:grouping>
                </mx:GroupingCollection>
            </mx:dataProvider>        
            
            <mx:columns>
                <mx:AdvancedDataGridColumn dataField="Region"/>
                <mx:AdvancedDataGridColumn dataField="Territory"/>
                <mx:AdvancedDataGridColumn dataField="Territory_Rep"
                    headerText="Territory Rep"/>
                <mx:AdvancedDataGridColumn dataField="Actual"/>
                <mx:AdvancedDataGridColumn dataField="Estimate"/>
            </mx:columns>
       </mx:AdvancedDataGrid>
    </mx:Panel>
    
</mx:Application>

Open in new window

Avatar of YossiBa
YossiBa

ASKER

well, no,
It creates a parent column (Region) and its sub parent (Territory).
What I need is to make Region as the logic parent but the only parent column visible is Territory.
Region should look as a child
>> What I need is to make Region as the logic parent
>> Region should look as a child
So you want Region to be the logic parent of Territory, while you want to see it as a child of Territory?
Why do you want to see the parent-child relation otherwise then it really is?
Do you mean this?
I really don't get it, I think.
Could you draw it somehow?
        <mx:AdvancedDataGrid id="myADG" 
            width="100%" height="100%" 
            initialize="gc.refresh();">        
            <mx:dataProvider>
                <mx:GroupingCollection id="gc" source="{dpFlat}">
                    <mx:grouping>
                        <mx:Grouping>
                       	    <mx:GroupingField name="Territory"/>
                            <mx:GroupingField name="Region"/>
                            
                        </mx:Grouping>
                    </mx:grouping>
                </mx:GroupingCollection>
            </mx:dataProvider>        
            
            <mx:columns>
                <mx:AdvancedDataGridColumn dataField="Territory"/>
                <mx:AdvancedDataGridColumn dataField="Region"/>
            </mx:columns>
       </mx:AdvancedDataGrid>

Open in new window

Avatar of YossiBa

ASKER

Yes, it sounds stupid but we have already an old application using html and there this attributes:
HirarchyColumnId (Teritory in our case)
ParentId(Region),

The user can switch between Hirarchy ids, but the parent will always remain the logic parent.
This is actualy done in TreeGrid if we drag a column to be the first field, it becomes the hirarch column,
can we do that in code?

Thanks for your help
Avatar of YossiBa

ASKER

Well I have come a cross a very crucial issue I have problem with,
frankly its more importent and of course I will raise my granted points :))) if you can help me here.
I am using ItemRenderer for my grid and RemoteObject to retrieve the data to the grid.
When first loaded I create a new RemoteObject and display the grid.
How can I do a lazy loading using the ItemRenderer to retrieve the relevant data from the server of the parent and childs?
should I create a new RemoteObject? but where do I place it in the renderer?

This is very importent to me, if you can help me here,
Please

Thanks man

Jo
Avatar of YossiBa

ASKER

This is the max point I've got :(
>> This is the max point I've got :(
That's no problem.

>> How can I do a lazy loading using the ItemRenderer to retrieve the relevant data from the server of the parent and childs?
Lazy loading is a matter of going (once) to the server only when needed.

some kind of:

private var _data:YourData = null;

private function get dataToVisualize():YourData {
     if (_data==null) {
         _data = .... // get it by going to the server
     }
     return _data;
}
Avatar of YossiBa

ASKER

thanks for the help,
Should this routine be in the ItemRenderer? where?
for retrieving the exact data when I open a parent node (to show all its childrens) I need to know what node was clicked, where do I get it from?
The follwing function(in my ItemIRenderer) is executed when I click on a parent node:
       public function set listData(value:BaseListData):void
        {
             _listData = DataGridListData(value);
        }

I think I need to replace the value by going to the server, I can do that by creating a new RemoteObject and get the relevant data by sending the parent id,
How do I get this parentId?

I have lots of Q's :((
Please advise if you can

Thanks man :)
>> I need to know what node was clicked, where do I get it from?
out of the datagrid

       public function set listData(value:BaseListData):void {
             _listData = DataGridListData(value);
             var dg:DataGrid = DataGrid(_listData.owner);
             // now you can get the selected row and out of that you can probably het the parent id
        }
Avatar of YossiBa

ASKER

Ok,
SO if I understand you it should look something like that:
public function set listData(value:BaseListData):void {
             _listData = DataGridListData(value);
             var dg:DataGrid = DataGrid(_listData.owner);
             
           var dataService:RemoteObject;
          dataService = new RemoteObject("MyHandler2");
         ....
         ....
         // retrieving the new data from the server
          dg.dataProvider = myNewLimitedDataProvider
         var openNodes:Object = IHierarchicalCollectionView(adg.dataProvider).openNodes;
        adg.validateNow();
         IHierarchicalCollectionView(adg.dataProvider).openNodes = openNodes;
        }

Never tried that....
is that sims correct?
should it all be in this function?
should i update  _listData  again?

Thanks man
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YossiBa

ASKER

I will try that,
my last question realy :))
As you've seen, I created the RemoteObject, now I need to activate it manualy
what should I do to fire the remoteObject to get my data back?

Thanks a lot man, you realy helped me
>> what should I do to fire the remoteObject to get my data back?
Sorry, I don't know.
You'll have to search for documentation on how to work with RemoteObjects
Thanx 4 axxepting