Skip navigation
Currently Being Moderated

Building DataGrid dynamically

Jul 4, 2013 3:27 PM

Tags: #dynamic #spark #datagrid #flex4

Hi,

 

I am getting data from the database via XML (SOAP Web Service),

and in that case I don't know number of columns or their names.

Need to display them in Spark DataGrid (and allow user to add, edit, delete rows).

 

The complication I see here is that in that project there is Parsley + proprietary corporate

Flex/Java soap framework, so I normally know a Value Object and get a Vector of rows, converting it into a ResultSet to process.

 

in Parsley Command:

public function result(event:ResultEvent) {

  var rs:Vector.<Object> = ServiceUtils.extractResultSet(event.result, ValueObject);

...

}

 

But in that case there is no static Value Object.

 

Is there a way to create dynamic Value Objects?

 

 

Can you tell me how can I retrieve Columns (metadata) from XML (length and Column Names) ?

 

 

Please help!

 

 

TIA,
Oleg.

 

 

 

--
Thank you,
Oleg.
 
Replies
  • Currently Being Moderated
    Jul 16, 2013 4:19 AM   in reply to olegkon
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 16, 2013 6:12 AM   in reply to olegkon

    Are you sorting somewhere? It should come the way you want it.

    You can sort the arrayCollection with:

    http://flex-apollo.blogspot.com/2009/07/sorting-arraycollection.html

    Best,

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 17, 2013 6:36 AM   in reply to olegkon

    Very interesting, the same behavior happens in advanced Datagrid.

    Here is my solution:

     

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                
                import spark.components.gridClasses.GridColumn;
                
                [Bindable]
                private var dpFlat:ArrayCollection = new ArrayCollection([
                    {Territory:"Arizona", Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000}, 
                    {Territory:"Arizona", Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000},  
                    {Territory:"Central California", Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000},  
                    {Territory:"Nevada", Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000},  
                    {Territory:"Northern California", Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000}, 
                    {Territory:"Northern California", Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000},  
                    {Territory:"Southern California", Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000}, 
                    {Territory:"Southern California", Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
                ]);
                
                [Bindable]
                public var myArray:Array = ["Territory", "Territory_Rep", "Actual", "Estimate"];
                
                [Bindable]
                private var gridColumns:ArrayCollection = new ArrayCollection();
                
                private function init():void{
                    
                    for each (var field:String in myArray)
                    {
                        var myColumn:GridColumn = new GridColumn(field);
                        gridColumns.addItem(myColumn);
                    }
                    gridColumns.refresh();
                    myADG.columns = gridColumns;
                }
                
            ]]>
        </fx:Script>
        <s:DataGrid id="myADG" editable="false" width="100%" height="100%" dataProvider="{dpFlat}">
        </s:DataGrid>
    </s:Application>
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 23, 2013 11:31 AM   in reply to olegkon

    What is the full stack trace for the error?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 15, 2013 6:56 AM   in reply to jfb00

    This is wonderful

    1. BUT I have other AdvanceDGs in the same form and application! so how to make the above creationComplete="init()" to be applied to "a" specific ADG? Right now I am seeing compilation errors on all the other ADGs in my IDE.
    2. And this requirement comes from a need to have "a" Data Entry form automagically  generated using the above  Array column names, ANY Such sample code tying the ADG Column Names to generate a form items in a form will help. Basically I am trying to create a metadata for a Table and a Date Entry form for pulating that table!!
    3. How can I modularize  the above specific code in separate MXML file for the ADG (say dynamicADGColumnProvider.xml) and reference the ADG MXML back in the main Application mxml? basically creating a hierarchy of mxmls for each of the ADGs separately

    Thanks for your reply.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points