Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Advance DataGrid on the-fly

    Hi there coders,

    I'm learning flex about a week or two. Am using Flex 4, may I ask some guidance of creating a component on-the-fly particularly an advancedatagrid object.

    This advancedatagrid will have an advancedcolumn and advancecolumngroup on it. Please show me the right way to do this on-the-fly.


    Best Regards!

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You can see an MXML example here. This is (almost) the same thing in pure AS3:
    Code:
    import mx.collections.ArrayCollection;
    import mx.collections.Grouping;
    import mx.collections.GroupingCollection2;
    import mx.collections.GroupingField;
    import mx.controls.AdvancedDataGrid;
    import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
    
    private function init():void
    {
        
        var testData: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}
        ]);
    
        
        var myADG:AdvancedDataGrid = new AdvancedDataGrid();
        myADG.columns = new Array(new AdvancedDataGridColumn('Territory'), new AdvancedDataGridColumn('Territory_Rep'), new AdvancedDataGridColumn('Actual'), new AdvancedDataGridColumn('Estimate'));
        
        var myGroup:Grouping = new Grouping();
        myGroup.fields = new Array(new GroupingField('Region'), new GroupingField('Territory'));
        
        var myGroupingCollection:GroupingCollection2 = new GroupingCollection2();
        myGroupingCollection.source = testData;
        myGroupingCollection.grouping = myGroup;
        myGroupingCollection.refresh();
        
        myADG.dataProvider = myGroupingCollection;
        myADG.validateNow();
        
        container.addElement(myADG);
    }
    "container" is the ID of the element you want to append the ADG to.

  • #3
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks maaan...! I will test this when I get home.

    Got a question. How am I going to render a textbox in the AdvancedDataGrid header or shall I say columngroup?
    Last edited by pasensyoso_mani; 09-14-2010 at 06:18 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •