Displaying DataTips when using an itemRenderer
One of the bad things about using itemRenderers in a DataGridColumn is that you lose the dataTip functionality that it normally provides. Well, here is a way to fake that functionality.
First, add the dataTipField or dataTipFunction to the DataGridColumn like you normally would.
showDataTips="true"
dataTipField="description1" />
Then, in your itemRenderer add the following code to be able to tap into that information and display a tooltip instead.
private function getToolTip():String{
var func:Function = dg.columns[listData.columnIndex].dataTipFunction;
if(func != null){
}else if(dg.columns[listData.columnIndex].dataTipField.length){
}else{
}
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
this.toolTip = getToolTip();
}
This works with both dataTipFields and dataTipFunctions and lets you treat the dataTips in your columns the same way, regardless of whether you’re using an itemRenderer or not. The only minor difference is the positioning of the label, but that can be easily modified with styles. You can download the full source code here, for a functional example of how this works.
Tags: dataGridColumn, dataTipField, dataTipFunction, DataTips, itemRenderer
Wow! You saved hours of research. This was exactly what I was looking for. Thanks a ton!
Nice work! Thanks!
It went clean to an AdvancedDataGrid, except I had a first line in the getToolTip() function:
if (listData == null) return “”;
Can you point to an example of the styles code mentioned? “The only minor difference is the positioning of the label, but that can be easily modified with styles.”
Thanks,
Thank you so much, I have been struggling with my datatips getting trashed by their item renderer. You are awesome!
@Andrew,
I’ve never had to do it myself, but you should probably manually position the tooltip as described in this post and it’s comments.
http://blogs.adobe.com/flexdoc/2007/05/positioning_tooltips_1.html
[...] beim verwenden von ItemRenderern versagt. (Dabei hatte dann aber das hier ausgeholfen: Displaying DataTips when using an itemRenderer | Kalen Gibbons). Dann steh ich aber doch immer noch vor dem selben Problem, denn die unter [...]
Thank you for publishing your solution. It is a great general approach to the problem and proved very useful!
Thnx a million for this soln!