2 Replies Latest reply on May 16, 2013 11:36 PM by Szalejot

    Populate AdvancedDataGrid with dynamic objects

    Szalejot

      I have following situation:

      My component will receive data to be populated into AdvancedDataGrid. MyList is ArrayCollection of objects to populate. Each MyObj has myPropList which is ArrayCollection. MyPropList contains MyProp, which have fields like name and value.

      I want names of MyProps to be headers and values to be values in cells. I do not know how many names I will receive, but I know, that for every MyObj its MyPropList contains the same number of MyProps with the same order.

       

      Code that I tryied:

       

                  var items:ArrayCollection = new ArrayCollection();

                  var firstItem:Boolean = true;

                  for each (var obj:MyObj in myList) {

                      if (firstItem) {

                          firstItem = false;

                          var columns:Array = new Array();

                          for each (var prop:MyProp in obj.myPropList) {

                              var col:AdvancedDataGridColumn = new AdvancedDataGridColumn();

                              col.dataField = "value";

                              col.headerText = prop.name;

                              col.editable = false;

                              col.sortable = true;

                              columns.push(col);

                          }

                          parametersGrid.columns = columns;

                      }

                      items.addItem(obj.myPropList);

                  }

                  parametersGrid.dataProvider = items;

      This code generates columns, but do not populate data. Where I do mistake?

       

      PS. I am using flex 3.5

       

      ------

      EDIT:

      I have made change, but after that I see MyProp.toString in cell and not value of MyProp.value field.

       

                  var items:ArrayCollection = new ArrayCollection();

                  var firstItem:Boolean = true;

                  for each (var obj:MyObj in myList) {

                      if (firstItem) {

                          firstItem = false;

                          var columns:Array = new Array();

                          var cnt:int = 0;

                          for each (var prop:MyProp in obj.myPropList) {

                              var col:AdvancedDataGridColumn = new AdvancedDataGridColumn();

                              col.dataField = "0." + cnt + ".value";

                              cnt++;

                              col.headerText = prop.name;

                              col.editable = false;

                              col.sortable = true;

                              columns.push(col);

                          }

                          parametersGrid.columns = columns;

                      }

                      items.addItem(obj.myPropList);

                  }

                  parametersGrid.dataProvider = items;