3 Replies Latest reply on Jun 9, 2009 8:22 AM by *Prashant Shelke*

    Displaying dynamic values in datagrid

    Sangeetha AV Level 1

      I have an arraylist. Each row in the arraylist is a VO which in turn contains the information for a row in the datagrid.


      Iam returning this arraylist from Java class. The columns are dynamic so we cant predict which are the columns the arraylist has.


      Iam using <mx:AdvancedDataGrid> control.  How do I bind the ArrayList with the datagrid and further iterate the arraylist to access the VO's.


      How can I bind the <mx:AdvancedDataGridColumn> with each of these VO's and display the values dynamically?

        • 1. Re: Displaying dynamic values in datagrid
          *Prashant Shelke* Level 4

          I think you have to use ArrayList[Array[Value 1, Value 2, Value 3... so on]] bcoz if u are using arrayList of VOs & VOs are static in nature number of attributes are Fixed.


          So on client side, dont assigned any dataField it will take from ArrayList[Array[]] in this case dataFields will become as 0, 1, 2... like this. You can search for dynamic classes in actionscript for more feasible solution.



          1 person found this helpful
          • 2. Re: Displaying dynamic values in datagrid
            Sangeetha AV Level 1

            Thanks for the suggestion.Could you please give me some code examples.

            • 3. Re: Displaying dynamic values in datagrid
              *Prashant Shelke* Level 4

              Hi Sangeetha,


              Please refer following link, & ensure your sending ArrayList of Array & array of header texts(means how many number of datagrid columns you want!)

              Hope this will work for you & let me knw if u have any more queries.


              http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-contr ol-in-flex/




              var dataGridColumns: = new DataGridColumn;
              for(var j:int = 0; j<arrColumnHeaderText.length;j++)/* arrColumnHeaderText is array of Header like ["Emp Name", "Emp Address"]**/
                            dataGridColumns = new DataGridColumn;


                            var customHeader:ClassFactory = new ClassFactory(MyCustomHeader);  /** MyCustomHeader is any item renderer u want to set to dataGridColumn*/
                             dataGridColumns.headerRenderer = customHeader;
                             //Set the Width over here                        
                             headerColumnWidth = 100;
                             strHeaderName = arrColumnHeaderText[j];
                             if(strHeaderName != "")
                                 dataGridColumns.headerText = strHeaderName;
                                 if(arrColumnHeaderText[j] != "My Shipments")
                                     dataGridColumns.headerText = arrColumnHeaderText[j];
                      /** column wise style here can set */
                             if(dataGridColumns.headerText == "SHIPMENT.PICKUP_STOP" || dataGridColumns.headerText == "SHIPMENT.DEL_STOP")
                                 if(dataGridColumns.headerText != null && dataGridColumns.headerText != "" )
                      dgShipmentSearch.columns = columns; // setting columns to dataGrid.