1 Reply Latest reply on Sep 16, 2008 4:19 PM by ntsiii

    ArrayCollection to AdvancedDataGrid programatically

    eexposito
      I have a single datagrid that I want to use to display results from DB queries via a web service. So I don't know ahead of time what my columns are going to be. I would like to display the results in my grid and possibly assign an itemRenderer based on the column names of the query. So I have this function below I am working on and think I am on the right path but need some help with the details:

      private function FillDataGrid():void
      {

      var dgColumns:Array = new Array();
      var acDbResults:ArrayCollection = WSGetDBResults();
      var colName:String = null;

      // I know this is wrong so don't laugh too hard :)
      // Would like to loop through columns in ArrayCollection
      for( var i:int = 0; i<acDbResults.length;i++)
      {
      colName = acDbResults.getItemAt(i).toString();
      var c1:AdvancedDataGridColumn = new AdvancedDataGridColumn(colName);
      c1.dataField = acDbResults.getItemAt(i).something;

      switch(colName)
      {
      case "status":
      c1.itemRenderer = new ClassFactory(externalRenderer1);
      break;
      case "name":
      c1.itemRenderer = new ClassFactory(externalRenderer2);
      break;
      case "age":
      c1.itemRenderer = new ClassFactory(externalRenderer3);
      break;
      }

      dgColumns.push(c1);
      }

      myDataGrid.columns = dgColumns;
      myDataGrid.dataProvider = acDbResults;
      myDataGrid.invalidateDisplayList();
      }

      Thanks,
      EE