1 Reply Latest reply: Jul 6, 2012 6:02 AM by Faizal-786 RSS

    ToolTip for AdvancedDataGrid

    YuHsin4221123

      Hello,

       

      I would I to ask how to create a tooltip in AdvancedDataGrid.

      My MXML component is a VBox based component.

       

      This is the code for my custome ToolTip using Panel:

       

      <fx:Script>

       

         <![CDATA[

       

          import mx.controls.Alert;

          import mx.events.FlexEvent;      

       

          [Bindable]

       

          public var _dataId:String;

          protected function dataGrid_creationCompleteHandler(event:FlexEvent):void

          {

              var dataid:String;

              dataid = _dataId;

              getSpecificUserDataCResult.token = twitterSentimentManager.getSpecificUserDataC(dataid);

          }

       

       

          protected function dataGrid2_creationCompleteHandler(event:FlexEvent):void

          {

              var dataid:String;

              dataid = _dataId;

              getSpecificUserDataUResult.token = twitterSentimentManager.getSpecificUserDataU(dataid);

          }  

       

          ]]>

      </fx:Script>

       

       

       

       

      This is the code for AdvancedDataGrid:

       

      <fx:Script>

       

          <![CDATA[

              import mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer;

              import mx.events.FlexEvent;

              import mx.events.ListEvent;

              import mx.events.ToolTipEvent;

              import spark.components.IItemRenderer;     

       

              private function createCustomToolTip(event:ToolTipEvent):void {

                      var toolTip:CustomToolTip = new CustomToolTip();

                      toolTip._dataId = event.target.data;

                      event.toolTip=toolTip;

                  }

       

              private function createCustomToolTip(event:ToolTipEvent):void {

                  var toolTip:CustomToolTip = new CustomToolTip();

                  var dataid:String = AdvancedDataGridItemRenderer(event.itemRenderer).data.userID;

                  toolTip._dataId = dataid;          

                  event.toolTip=toolTip;

              }

       

              ]]>

       

      </fx:Script>

       

      <mx:AdvancedDataGrid x="48" y="50" id="myADG" designViewDataType="tree" data="myADG.currentItem" toolTipCreate="createCustomToolTip(event)" selectedIndex="0" creationComplete="myADG_creationCompleteHandler(event)" dataProvider="{getSpecificCountryCollection}">

       

          <mx:columns>

              <mx:AdvancedDataGridColumn headerText="sentiment" dataField="sentiment"/>      

              <mx:AdvancedDataGridColumn headerText="userID" dataField="userID"/>

              <mx:AdvancedDataGridColumn headerText="dateTime" dataField="dateTime"/>

          </mx:columns>

       

      </mx:AdvancedDataGrid>

      </s:TitleWindow>

       

      It didnt show any error, but nothing happen when mouseover.

      I dont know which part is wrong?

       

      Thank You!

        • 1. Re: ToolTip for AdvancedDataGrid
          Faizal-786

          Hi,

           

          I see that this question is unanswerd for a while, and I came across it when I encountered the same problem.

          If you want to acheive the tootip for each CELL in the datagrid then you can use the ItemOver listener

           

          setup the listener:

           

          dg.addEventListener(ListEvent.ITEM_ROLL_OVER , itemOver);

           

          define itemOver:

           

          public function itemOver(event:ListEvent):void

                      {

                          var toolTipText:String                = (AdvancedDataGridItemRenderer)(event.itemRenderer).text; //only if you want to show the text in the cell itself as the tooltip

                          (AdvancedDataGridItemRenderer)(event.itemRenderer).toolTip    = toolTipText;

                      }

           

          and thats all you have to do.

           

          Regards

          Faizal