Ticket T605656
Visible to All Users

TreeView - How to show Tooltip for each node

created 7 years ago

Hi,

I can't find a solution to my angular 2+ problem.

I have a treeview bound to flat data. Now I want to show a tooltip when hovering a node with specific data from that node (e.g. tooltip value of the flat data row) .

Any idea how I can solve this using DevExtreme?

Greetings,
Sigurd

Answers approved by DevExpress Support

created 7 years ago (modified 7 years ago)

Hello Sigurd,

You can find all items in the dxTreeView.onContentReady event handler and subscribe to the "mousenter" event of each item. Then, change the content of your tooltip based on the item value and specify the dxTooltip.target option before showing the tooltip. So, your code might be as follows:

https://plnkr.co/edit/ACOnSLho0ZbAXYpt1D3j?p=preview

HTML
<div class="form"> <dx-tooltip [target]="target" [(visible)]="isVisible"> <div *dxTemplate="let data = data of 'content'"> <span>{{tooltipContent}}</span> </div> </dx-tooltip> <dx-tree-view id="simple-treeview" [dataSource]="products" dataStructure="plain" parentIdExpr="categoryId" keyExpr="ID" displayExpr="name" (onContentReady)="onContentReady($event)" ></dx-tree-view> </div>

TS:

JavaScript
tooltipContent: string; target: any; isVisible: boolean = false; onContentReady(e: any) { let elements = e.component.element().querySelectorAll(".dx-treeview-item"); let that = this; elements.forEach((el, index) => { el.addEventListener("mouseenter", event => { that.tooltipContent = e.component.getDataSource().items()[index].name; that.target = event.target; that.isVisible = true; }); }); }
    Comments (2)

      Hi, that seems to work.

      How can we apply HTML coding for the content?
      E.g. 1 node could be '<h1>Title</h1><p>some text</p> ' while another node can have a different tooltip content without header but an image or so

        Got it working thx!

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.