1 Reply Latest reply on Aug 9, 2009 12:27 AM by $Nith$

    Create datagrid dynamically

    jeepin95

      I'm new to Flex (just started looking at it 2 days ago) but I've been working on this problem all day long. I'm trying to create and populate a datagrid based on field names specified in a CSV list, with separate data that is also going to be CSV but from a different source in the same order if that makes sense.

       

      I've figured out how to make the green code below work as I would expect, buildDG takes the CSV string and generates the columns and headers in the datagrid like I want. The part I need help on is getting the code in red to work, a function that will accept CSV data in the same order as the headers and add that data as a new row in the datagrid. I've been working on this all day and can't figure out how to do this.

       

      Any help would be greatly appreciated. Thanks, Josh

       

       

      private function init():void

      {

      buildDG("Col1,Col2,Col3,Col4,Col5,Col6");

      }

       

      private function buildDG(sCSV:String):void

      {

      var aCSV:Array = sCSV.split(",");

      for ( var i:int = 0; i < aCSV.length; i++)

      {

      var dgc:DataGridColumn = new DataGridColumn(aCSV[i]);

      var cols:Array = dgCSV.columns;

      cols.push(dgc);

      dgCSV.columns = cols;

      }

      }

      private function addDGRow(sCSVData:String):void
      {
      // Code for adding a row to the datagrid assuming sCSVData is CSV data in the same order as sCSV above
      }
      ...
      <mx:DataGrid id="dgCSV">
      </mx:DataGrid>