2 Replies Latest reply on Dec 27, 2006 10:53 AM by ntsiii

    Pass param to an itemrenderer

      I have a datagrid where every column has an itemrenderer defined in a .mxml file
      mydataArray[0] = {cl1: "company A", cl2: "KO", color2: 0xff0000, cl3: "OK", color3: 0x00FF00};
      mydg.dataProvider = mydataArray;
      <mx:DataGrid id="mydg" x="29" y="10" width="300" height="184">
      <mx:DataGridColumn headerText="Column 1" dataField="cl1"/>
      <mx:DataGridColumn itemRenderer="ColoredCell" wordWrap="true" headerText="Column 2" dataField="cl2"/>
      <mx:DataGridColumn itemRenderer="ColoredCell" wordWrap="true" headerText="Column 3" dataField="cl3"/>


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" backgroundColor="{cellColor}">
      [Bindable] private var cellColor:Number;

      override public function set data( value:Object ) : void
      super.data = value;
      cellColor = data.color2;
      <mx:Text width="100" text="{data.cl2}" />

      Since I have some columns, I don't want to use a different itemrenderer for each one. But I want to use just one ColoredCell.mxml
      How can I tell to ColoredCell.mxml, column by column, which array column to use?
      In other words, how can I know in my cellrenderer that I have to get values from data.cl2 and color from data.color2, instead of data.cl3 and data.color3 and so on? In this way if I have 10 columns, I don't need to create 10 different ColoredCellX.mxml

      Thanks a lot in advance.