Custom Itemrender in Datagrid with Datatip

I have a datagrid with one datagridcolumn in it. Without a custom itemrenderer, I can use the datatip function to show the custom data type, but now I want to have a custom renderer to color the rows differently. So I extended the label and changed the data method, but now my datatip function doesn't work anymore.

Any ideas?

early

Sebastian

+2


source to share


4 answers


I know this question is a bit old, but I just ran into the same problem and solved it by looking at how the standard DataGridItemRenderer class does it.

So basically I ended up copying this toolTipShowHandler () function into my class (without any changes), implementing the IDropInListItemRenderer interface, and adding a few lines to my commitProperties () function, which were also inspired by DataGridItemRenderer.



Hope it helps.

+1


source


I'm a little late to the party but I ran into this issue with a custom DataGridItemRenderer for images. The solution described in the following link worked out nice for me:

http://www.kalengibbons.com/blog/index.php/2008/12/displaying-datatips-when-using-an-itemrenderer/



The bottom line is that you override the rendering itemDisplayList () and set the tooltip by calling the dataTipFunction and / or using dataTipField in the same way as inline item rendering.

+1


source


copying the content of the link given by cbranch here. stackoverflow is more reliable for storing code snippets

Displaying tooltips when using itemRenderer

One of the bad things about using itemRenderers on a DataGridColumn is that you lose the dataTip functionality it usually provides. Well, here's a way to spoof this functionality.

First add dataTipField or dataTipFunction to DataGridColumn as usual.

<mx:DataGridColumn  headerText="DataTip"
      dataField="name1"
      showDataTips="true"
      dataTipField="description1" />

      

Then in your itemRenderer add the following code to be able to use this information and display a tooltip.

private function getToolTip():String{
    var dg:DataGrid = listData.owner as DataGrid;
    var func:Function = dg.columns[listData.columnIndex].dataTipFunction;
    if(func != null){
           return func.call(this, this.data);
    }else if(dg.columns[listData.columnIndex].dataTipField.length){
           return data[dg.columns[listData.columnIndex].dataTipField];
    }else{
           return "";
     }
 }

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
     super.updateDisplayList(unscaledWidth, unscaledHeight);
     this.toolTip = getToolTip();
  }

      

This works with both dataTipFields and dataTipFunctions and allows you to treat the data in the columns in the same way whether you are using itemRenderer or not. The only minor difference is the positioning of the label, but this can easily be changed with styles. You can download the complete source code here for a functional example of how it works.

source

+1


source


Off the top of my head, perhaps do your custom rendering of the elements with an extended DataGridColumn. This will give your element renderer all the functionality of a regular column.

-2


source







All Articles