1 Reply Latest reply on Oct 18, 2006 4:36 AM by ju2999

    DataGrid dynamically with a Repeater

    ju2999
      Hello,

      I would like to create a DataGrid component that is created dynamically with the help of a Repeater array.

      I gave up my first approach using directly a <mx:Repeater> tag within the DataGridColumns:


      Code:

      <mx:DataGrid ..>
      <mx:columns>
      <mx:Repeater id="rp" datProv="{data}"...>
      <mx:DataGridColumn dataField="{rp.currentItem.dataField}" .... />
      </mx:Repeater>
      </mx:columns>
      </mx:DataGrid>

      This kind of recurive structure isn't allowed.

      then I tried to resolve my problem by using an ActionScript generator, but because of a lack of example code, I don't know what's wrong with it:

      Code:

      <mx:DataGrid xmlns:mx=" http://www.adobe.com/2006/mxml" columns="{repeaterArray}" initialize="initApp()"...>
      <mx:Script>
      <![CDATA[
      import mx.controls.dataGridClasses.DataGridColumn;
      ...
      public function initApp():void {
      repeaterArray = new Array();
      for (var c:Number = 0;c < ids.length;c++) {
      var newObj:DataGridColumn = new DataGridColumn(null);
      newObj.dataField = String(ids[c]);
      newObj.headerText = String(headers[c]);
      newObj.width = Number(widths[c]);
      repeaterArray.push(newObj);
      }
      }
      ]]></mx:Script>
      </mx:DataGrid>


      ids, headers, width are passed arrays with needed Strings, bzw. Numbers. It doesn't work although there is neither an compiler nor a debug error.

      I also dunno if I should use the initialize or creationComplete - event or another one?

      Does anybody know how I use the Repeater in this case correctly or build a working ActionScript generator?

      Thank you.