5 Replies Latest reply on Nov 12, 2010 7:35 AM by darl2

    How to make tooltip for DataGridColumn

    LordPathogen Level 1
      Hi, I'm trying to get a tooltip for whenever the user mouses over a column header in a DataGrid. I've seen some talk about creating my own ItemRenderer to do this but looking at the Flex docs, I see that the existing DataGridItemRenderer for a DataGridColumn has a tooltip attribute but I have been unsuccessful in getting it to work. Should I in fact make my own ItemRenderer or is there any way to expose it in the existing DataGridItemRenderer? Can anyone advise what the best way to do this is? Thanks!
        • 1. Re: How to make tooltip for DataGridColumn
          ntsiii Level 3
          Look at "dataTip" to see if that might be what you need.
          Tracy
          • 2. How to make tooltip for DataGridColumn
            LordPathogen Level 1
            Hi Tracy, thanks but I looked at dataTip before and it's not what I am looking for. As I understand it, that is for the actual data of a DataGrid. What I am looking for is a tooltip for the header of a DataGrid. I want the user to be able to mouse over the grid header and see as a tooltip the equation behind the calculated data values in the grid cells. I took a stab at this myself by extending DataGridColumn like so:

            public class NewDataGrid extends mx.controls.dataGridClasses.DataGridColumn{

            public function set headerToolTip(tip:String):void{
            headerRenderer.toolTip = tip;
            }
            }

            This does not work. In fact, it seems to hose up the VM such that it becomes unresponsive... Does anyone have any ideas? Thanks
            • 3. Re: How to make tooltip for DataGridColumn
              ntsiii Level 3
              Have you tried creating an itemRenderer for the Header? I'd try that route before subclassing.

              Tracy
              • 4. Re: How to make tooltip for DataGridColumn
                LordPathogen Level 1
                Hi Tracy, yeah I just got it working like this:

                <mx:DataGridColumn resizable="true" dataField="@period" textAlign="right">
                <mx:headerRenderer>
                <mx:Component>
                <mx:Text text="period" toolTip="This is a test"/>
                </mx:Component>
                </mx:headerRenderer>
                </mx:DataGridColumn>

                Seems like a lot of "bulk" just to get a tool tip working ;-) I was wanting to make a reusable component that I could set the headerRenderer attribute of DataGridColumn to, hence I thought it would make sense to subclass the existing DataGridColumn to manually set the tool tip since its DataGridItemRenderer has a toolTip attribute. Still not really sure why my previous code does not work...
                • 5. Re: How to make tooltip for DataGridColumn
                  darl2

                  We can do like this:

                   

                  l_DataGridColumn.headerRenderer=new ClassFactory(YourHeaderItemRenderer);// use custom renderer instead of the default DataGridItemRenderer

                   

                  And in you class YourHeaderItemRenderer extends DataGridItemRenderer, you can override some method:

                   

                  override public function set toolTip(value:String):void {

                       //set toolTip value here:    

                       toolTip= "column description";

                  }

                   

                  this one is not dynamic, so if we want to,  we can extend the DataGridColumn to add the toolTip field, and use it:

                   

                  l_DataGridColumn.headerRenderer=new ClassFactory(YourHeaderItemRenderer);// use custom renderer instead of the default DataGridItemRenderer

                  l_DataGridColumn.toolTip="compute it here";

                   

                   

                  override public function set toolTip(value:String):void {

                       //set toolTip value here:    

                       toolTip= (data as YourDataGridColumn).toolTip;

                  }

                  Of course in this case, the dataGrid columns must use the YourDataGridColumn instead of DataGridColumn.
                  All that to have a toolTip for the column, it's sad :-)