2 Replies Latest reply on May 6, 2008 12:22 AM by Dema_In_Russia

    Object in Datagrid

    Dema_In_Russia
      Hello,

      I have following object (Class).

      public class CheckCanvas extends Canvas
      {
      var a:Check;
      var b:Check;
      public function CheckCanvas()
      {
      super();
      var f:UIComponent = this.parent as UIComponent;
      this.width = 120;
      this.height = 50;
      var a0:Check = new Check("docSel",false);
      a= a0;
      a.y = 5;
      a.x= 30;
      var b0:Check = new Check("docUnsel",false);
      b = b0;
      b.x = 80;
      b.y = 5;
      addChild(a);
      addChild(b);
      }
      }

      And I call this Object from Application throw datagrid
      <mx:DataGrid id="dataIn" dataProvider="{sourceDataIn}" >
      <mx:columns>
      <mx:DataGridColumn width="132" dataField="word" itemRenderer="source.CheckCanvas"/>
      </mx:columns>
      </mx:Datagrid>

      How can I get param from field "datafield" (in in the present state of affairs - "word") in my class (CheckCanvas) ???

      Please, help me.
        • 1. Re: Object in Datagrid
          peterskeeter
          In an itemrenderer you need to use this function

          override public function set data(value:Object):void {

          }

          to access the datagrid variable being rendered in your itemrenderer.
          Hence value will take on the object that gets passed into your itemrenderer.

          i.e
          here is an example of me using this function in an image itemrenderer a little ago..

          override public function set data(value:Object):void {
          this.removeAllChildren();
          if (value != null)
          {
          var r:Label = new Label();
          this.addChild(r);
          r.text = value.mylabel;
          var s:Image = new Image();
          s.source="desserts.jpg";
          this.addChild(s);
          }
          }

          In this case the datagrids datasource was this arraycollection.

          var mydata:ArrayCollection=new ArrayCollection([{mylabel:'A', path:'a.jpg'}, {mylabel:'B', path:'b.jpg'},{mylabel:'C', path:'c.jpg'},{mylabel:'D', path:'c.jpg'},{mylabel:'E', path:'c.jpg'},{mylabel:'F', path:'c.jpg'}]);

          so you can see how the araycollection has the "mylabel" field and how that is referenced in the itemrenderer..

          hope this helps..
          • 2. Re: Object in Datagrid
            Dema_In_Russia Level 1
            Thank, peterskeeter...
            all working...