3 Replies Latest reply on Aug 31, 2007 2:38 AM by Nerun

    Datagrid: Custom Itemrenderer


      my Datagrid consists of a variable number of columns that are handled by the same Itemrenderer. Now I have the problem that I can't find out which column I belong to when I am in the override set data function.

      Any hints how i can back track to what column the "current" Itemrenderer belongs or is processing at that moment?

      Thanks and GzG
        • 1. Re: Datagrid: Custom Itemrenderer
          I had the exact requirement. Multiple columns using the same item renderer and needing to know what was clicked. Essentially I solved it in three steps.

          1. Override the datagid to add your own custom events;
          package com.psc.eis.view
          import mx.controls.DataGrid;
          import mx.events.ListEvent;

          [Event( name = "MyViewCurrentEvent", type = "mx.events.ListEvent" ) ]
          [Event( name = "MyEditCurrentEvent", type = "mx.events.ListEvent" ) ]
          [Event( name = "MyDeleteCurrentEvent", type = "mx.events.ListEvent" ) ]
          [Event( name = "MySearchEvent", type = "mx.events.ListEvent" ) ]

          public class MyDataGrid extends DataGrid

          public function MyDataGrid() { super()}

          public static var MY_VIEW_CURRENT_EVENT:String="MyViewCurrentEvent";
          public static var MY_EDIT_CURRENT_EVENT:String="MyEditCurrentEvent";
          public static var MY_DELETE_CURRENT_EVENT:String="MyDeleteCurrentEvent";
          public static var MY_SEARCH_EVENT : String = "MySearchEvent";

          2. In your item renderer create a click handler that dispatches the appropriate event

          <?xml version="1.0" encoding="utf-8"?>
          <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml" horizontalAlign="center">

          private function clickHandler() : void
          import mx.events.ListEvent;

          var event:ListEvent = new ListEvent( MyDataGrid.MY_EDIT_CURRENT_EVENT );
          event.itemRenderer = this;
          <mx:Image id="imageDelete" source="images/bluepencil.gif" width="20" click="clickHandler()"/>

          3. In your mxml for the datagrid setup the event handler
          <psc:MyDataGrid id="dataGridProjects" dataProvider="{. . . . }"

          That's it.
          • 2. Re: Datagrid: Custom Itemrenderer
            Nerun Level 1
            Hello bitwyse,

            thanks for your response. As i understand your code, you provide your custom DataGrid with the ItemRenderer object as soon something is clicked in the renderer. That's very interesting and I'll keep that in the back of my head for possible future uses, but I just don't seem to understand how I could use this to solve my problem.

            Basically I need to know which column my ItemRenderer belongs to while I'm in the ItemRenderers overriden data function.

            Any hints you can give me are appreciated and thanks again for sharing your experience!

            • 3. Re: Datagrid: Custom Itemrenderer
              Nerun Level 1
              bort from flexforum.de gave me the answer. here's the short version:

              make your ItemRenderer implement "mx.controls.listClasses.IDropInListItemRenderer". the value you get in set listData(value:BaseListData) holds a field named columnIndex and that can be used to select the column from the parent grid.