adding tooltip to listbox

Hi Team,

I want to add tooltip to listbox, data in listbox is coming from an API, content of tooltip should be same as data displayed in listbox,
I have gone through these links but it's not working for me.

https://www.syncfusion.com/forums/156100/adding-image-beside-list-items-in-listbox

https://stackblitz.com/edit/angular-r4ajvf-wsgers?file=app.component.ts


Code : 

<ejs-listbox #metricslist id="metricslist" height='150px' [dataSource]='metricsListData'
                        formControlName="metricsList" [selectionSettings]="selection" [fields]='fields'
                        [class.disabledbutton]="disableMetricList" (change)="OnListItemSelect($event)">
                    </ejs-listbox>

 OnListItemSelect(args) {
    if (args.event.type === 'click') {
      let selectedItem = args.items;
      let selectedItemFormula = selectedItem.map(function (selectedItem) { return "[ " + selectedItem.name + " ]" })
      this.previousState.push(this.formula);

      if (this.formula.length < this.maxlength) {
        this.formula = (this.formula + selectedItemFormula).split("").slice(0this.maxlength).join("");
      }
}
}

so how can I add tooltip for the list box in my code.


Thanks,

Deepika.P



3 Replies 1 reply marked as answer

MK Mohan Kumar Ramasamy Syncfusion Team October 15, 2020 03:01 PM UTC

Hi Deepika, 
 
We have checked reported query, we can achieve your requirement using ngAfterViewChecked. Please refer the below sample link. 
 
 
Please let us know if you need any further assistance. 
 
Regards, 
Mohan kumar R 


Marked as answer

DE Deepika October 16, 2020 12:02 PM UTC

Thank you Mohan. 
 
The below code worked for me.
ngOnInit(): void {
this.getMetricListData();
}

 ngAfterViewInit() {
    this.tooltip = new Tooltip({
      content: "Loading...",
      target: ".e-custom-tooltip",
      beforeRender: this.onBeforeRender
    });
    this.tooltip.appendTo("body");
  }
  ngAfterViewChecked() {
    this.metricListTooltip();
  }

  onBeforeRender(argsTooltipEventArgs): void {
    this.content = args.target.textContent;
  }

 metricListTooltip(): void {
    if (this.metricsListData.length > 0) {
      let listLi = document.querySelector("#metricslist").querySelectorAll("li");
      let inumber;
      for (i = 0i < listLi.lengthi++) {
        var mySpan = document.getElementById("mySpan");
        mySpan.innerText = (listLi[ias any).innerText;
        listLi[i].classList.add("e-custom-tooltip");
      }
    }
  }


MK Mohan Kumar Ramasamy Syncfusion Team October 20, 2020 01:12 AM UTC

Hi Deepika,   
  
Thanks for the update.  
 
We are happy to hear that your requirement has been fulfilled. Please feel free to contact us if you need any further assistance on this. 
 
Regards, 
Mohankumar R 


Loader.
Up arrow icon