Creating a unique tooltip component for ag-grid with the use of Material tooltips

I am facing an issue with the current angular ag-grid tooltip example, as it is not functioning properly.

https://stackblitz.com/edit/angular-ag-grid-tooltip-example-fb7nko

Utilizing Javascript/typescript in Angular 8 with the latest ag-grid release. I have meticulously followed the plunker example but to no avail. In my CustomTooltipComponent, there is a dynamic mat-tooltip in the template that should display {{data}} from the .ts file. However, the tooltip does not appear. When I substituted it with a span tag, it displayed plain text. I have ensured that the created component is added to my entry and declaration modules.

<<<----   component that wants the tooltip --->

this.gridOptions = {
      deltaRowDataMode: true,
      getRowNodeId: (data) => data.name,
      onRowDoubleClicked: (data) => this.selectRow(data),
      rowSelection: 'single',
      defaultColDef: {
        sortable: true,
        resizable: true,
        tooltipComponentFramework: CustomTooltipComponent,
        tooltipValueGetter: (params: ITooltipParams) => params.data,
      }
    };

      this.columnDefs = [
        {
          headerName: 'Name',
          field: 'name',
          sort: 'asc',
         // tooltipField: 'name'
        }

<<<-------- tooltip component .ts ------->>>

import { Component } from '@angular/core';
import { ITooltipAngularComp } from 'ag-grid-angular';
import { ITooltipParams } from 'ag-grid-community';

@Component({
  selector: 'app-custom-tooltip',
  templateUrl: './custom-tooltip.component.html',
  styleUrls: ['./custom-tooltip.component.scss'],
})
export class CustomTooltipComponent implements ITooltipAngularComp {

  public params: ITooltipParams;
  public data: any;

  constructor() { }

  agInit(params: ITooltipParams): void {
    this.data = params.api.getDisplayedRowAtIndex(params.rowIndex).data;
  }

}

<<<----------- tooltip component .html ---->>>

<span matTooltip="{{data.name}}"></span>

<div>
<p><span>Name: </span>{{data.name}}</p>
<p><span>Created by: </span>{{data.createdBy}}</p>
<p><span>Modified by: </span>{{data.modifiedBy}}</p>

</div>

My expectation was to see a tooltip in mat-tooltip format and for the toolTipParams: () to function correctly with this approach.

Answer №1

Although it's not flawless, I managed to make it work by utilizing the cellRendererFramework as suggested by @adrian earlier. Here is a functional demonstration of my solution for incorporating a [matTooltip] with all its functionalities in an angular ag-grid custom component. This includes passing line breaks as a string array. I appreciate all the assistance!

Link to example on StackBlitz

Answer №2

When it comes to the issue with your data, it seems like there is a discrepancy between your StackBlitz setup and the question you are working on. Make sure that the properties in your data object match the casing of the properties in the row data; if you adjust fname to fName and lname to lName in tool-tip.component.html, you should see the data displayed correctly.

As for the material tooltip feature, typically you would apply a matTooltip attribute to an element (like a span) so that when you hover over it, a tooltip appears with the specified content. In this case, it seems like you are trying to display an element with a material tooltip inside the tooltip generated by ag-Grid, which is why you are only seeing plain text. If you want to use the material tooltip instead of ag-Grid's default rendering, you may have better success implementing a custom cell renderer.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How is it that cross-domain scripting is able to occur with local files on a smartphone or tablet?

My Experiment: To test cross-site scripting (XSS), I set up an index.html file with a xss.js script that utilized the jQuery.get() function. After opening the index.html in various browsers (Firefox, Chrome, IE, and Opera), I attempted to trigger an ajax ...

I am experiencing issues with the button click functionality in my Google extension

Greetings! I am currently developing a Chrome extension that will automatically redirect to my website and fill in the password. However, I am facing an issue with submitting the button click event. // Here is my manifest.json code { "name": "z", "v ...

Troubleshooting Electron Angular Application Connectivity Issues with API

While developing my ionic/angular app as an electron app, I encountered a problem when running it. After loading, I received the error message shown below: Refused to connect to 'https://xxxxxxxxxx.com/whpacking/v1/getlocations' because it violat ...

What steps can be taken to initiate Nx Release on the apps/* when modifications are made to the connected libs/* modules?

Trying out the nx release command but struggling to get it to release an app when there are changes to a dependent module. Examining the graph below, you can see that I have 3 apps, with 2 depending on the shared-ui module. https://i.sstatic.net/QYDBlRnZ.p ...

Conceal and reveal elements using v-if

Check out my fiddle: DEMO creating a new Vue instance: { el: '#app', data: { modules: ['abc', 'def'] } } I am looking for a way to hide or show elements using v-if based on the values in an array called modules[]. ...

Changing the MIME type of a JavaScript file in a Jade/Pug environment to text/html

Hi there, I've been experimenting with jade/pug to get my node.js backend to render the front-end pages. However, I'm facing some issues when trying to include JavaScript for certain functionalities. Whenever I try to load it, I encounter this er ...

How is it possible to leverage the CDN URL mechanism for package management when working with Typescript?

Is it possible to use a CDN URL pointing mechanism to resolve packages in Typescript? One example is the Material Icon package installation, which can be included using the following code: <link rel="stylesheet" href="https://fonts.googleapis.com/icon? ...

Is it advisable to incorporate both Jquery and AngularJs into progressive web applications?

Currently, I am in the process of constructing a progressive test application. So far, all the tutorials I have come across utilize native JavaScript. My inquiry is whether it is possible to leverage Jquery for streamlined code writing and implement an MVC ...

Canvas - Occasionally, using lineTo() can result in crisp edges in the drawing

I've created a simple Canvas drawing app. However, I've noticed that occasionally the lineTo() command generates a line with fewer coordinates, resulting in many edges: I'm currently using the latest version of Firefox - could this issue be ...

Steps to fix the postinstall error in Angular CLI

Can anyone lend a hand in resolving the following error? npm ERR! errno -4058 npm ERR! @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c4f40456c14021c021a">[email protected]</a> postinstall: `node ./bin/p ...

Issue with PrimeNG Carousel width on mobile devices

Currently, I am in the process of developing a system interface with Angular and PrimeNG specifically for mobile devices. The main requirement is to have a carousel to display a set of cards. After evaluating different options, I decided to utilize the ngP ...

@vue/cli for automated unit testing

I'm currently using @vue/cli version 4.5.15 and looking to write tests for my components. However, when I run the command, yarn test:unit I encounter an error that says: ERROR command "test:unit" does not exist. Do I need to perform additional se ...

Using TypeScript for Type Inference in Fetch Operations

I created a custom Fetch wrapper in Typescript to fetch data from my API. I am facing an issue where the retrieved data is of type "any" and I want to convert it to a specific type, like "user". Here is the link to my codesandbox for reference: https://co ...

ReactJS: Want to update card design by utilizing the onClick event handler

Currently, I am aware that there will be a need to refactor this code later on to separate things into their own components. However, due to time constraints, I have to wire this up as is at the moment. To achieve this, I utilized array.map() to create car ...

What is the process for including a dependency in an npm package in order to install another npm package?

As I work on creating an npm package for my Angular app, I find myself in need of including a dependency that already exists on npm. My dependency object will include the following entries: "dependencies": { "@angular/animations": "^6.1.0", "@angu ...

Implementing Routes in Express Using Typescript Classes

Seeking assistance in converting a Node.js project that utilizes Express.js. The objective is to achieve something similar to the setup in the App.ts file. In pure Javascript, the solution remains unchanged, except that instead of a class, it involves a mo ...

Having trouble with the ionic ion-nav-buttons not working on initial load?

My table view triggers the PixCtrl controller when a cell is clicked. If the connection is successful, data is retrieved using $http.get, otherwise sqlite is used. This setup works fine. However, I am facing an issue with my ion-nav-buttons being dynamic. ...

Emphasize the engaged menu selection when the page is refreshed

My application is a dashboard app built with React, Redux, and Antdesign. I utilized the layout provided by Ant design at https://ant.design/components/layout/. One issue I encountered is that when clicking on side menus, the active menu gets bold but upo ...

The data type returned by a method is determined by the optional parameter specified in the

I have a situation where I need to create a class with a constructor: class Sample<T> { constructor(private item: T, private list?: T[]) {} } and now I want to add a method called some that should return: Promise<T> if the parameter list ...

Freeze your browser with an Ajax request to a specific URL

There is a function in my view that transfers a value from a text box to a table on the page. This function updates the URL and calls another function called update_verified_phone(). The update_verified_phone() function uses a model called user_info_model( ...